Renzo
Renzo

Reputation: 87

ImageButton Disappearing

I have a VideoView and an ImageButton(Play Button for the video) where I record a video and play it using the ImageButton. Everything works fine but when I try to record again another video. The ImageButton disappears.

Here's my code:

public class MainActivity extends AppCompatActivity {

    ImageButton imageButton;

    static final int REQUEST_VIDEO_CAPTURE = 1;
    VideoView resultvideo;
    MediaController mediacontroller;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        resultvideo = (VideoView)findViewById(R.id.videoView);
        mediacontroller = new MediaController(MainActivity.this);

        mediacontroller.setAnchorView(resultvideo);

        resultvideo.setMediaController(mediacontroller);

        Button click = (Button)findViewById(R.id.buttonRecord);
        resultvideo = (VideoView)findViewById(R.id.videoView);
    }

    public void dispatchTakeVideoIntent(View v) {
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
            Uri videoUri = data.getData();
            resultvideo.setVideoURI(videoUri);

            resultvideo.pause();

        }
        imageButton = (ImageButton) findViewById(R.id.imageButton);
        {
            imageButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    resultvideo.start();
                    mediacontroller.show();
                    imageButton.setVisibility(View.GONE);
                }
            });
        }

    }
}

Upvotes: 1

Views: 176

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75645

Not sure why you expect other behaviour as the only setVisibility() call on that button you got in your code is:

imageButton.setVisibility(View.GONE);

so either remove that line or make button visible again when needed by calling

imageButton.setVisibility(View.VISIBLE);

EDIT

How do I make it disappear while the video is playing and call it back when the video is finish

Use MediaPlayer's OnCompletionListener

Upvotes: 1

Related Questions