ImageButton消失

时间:2017-08-30 18:47:08

标签: java android

我有一个VideoView和一个ImageButton(视频的播放按钮),我在其中录制视频并使用ImageButton播放。一切正常,但当我尝试再次录制另一个视频时。 ImageButton消失了。

这是我的代码:

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);
                }
            });
        }

    }
}

1 个答案:

答案 0 :(得分:1)

不确定为什么您期望其他行为,因为您在代码中对该按钮的唯一setVisibility()调用是:

imageButton.setVisibility(View.GONE);

因此,在需要时,通过调用

删除该行或使按钮再次可见
imageButton.setVisibility(View.VISIBLE);

修改

  

如何在视频播放时使其消失,并在视频播放完毕后将其回拨

使用MediaPlayer' OnCompletionListener