VideoView不会播放其他活动

时间:2017-09-01 15:32:55

标签: java android android-videoview

我有这个按钮,可以在另一个活动上播放视频,或者在Main2Activity中具体播放。问题是单击按钮时视频无法播放。一切都运转良好,我唯一的问题是当我点击那个按钮时。

MainActivity:

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

            resultvideo.setVideoURI(videoUri);
            mediacontroller.setAnchorView(resultvideo);
            resultvideo.pause();

        }
        buttonPlay = (Button) findViewById(R.id.buttonPlay);
        {
            buttonPlay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mediacontroller.show();
                    mediacontroller.setAnchorView(resultvideo);
                    resultvideo.start();
                }
            });
        }

        buttonFullScreen = (Button) findViewById(R.id.buttonFullScreen);
        {
            buttonFullScreen.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                    intent.putExtra("VIDEO_URI", videoUri.toString());
                    startActivity(intent);
                }
            });
        }
    }

Main2Activity:

public class Main2Activity extends Activity {

    Button buttonPlay;
    Button buttonFullScreen;
    static final int REQUEST_VIDEO_CAPTURE = 1;
    VideoView resultvideo;
    MediaController mediacontroller;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String uri = getIntent().getStringExtra("VIDEO_URI");
        Uri videoUri = Uri.parse(uri);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main2);

        resultvideo = (VideoView)findViewById(R.id.videoView2);

        resultvideo.start();

    }
}

1 个答案:

答案 0 :(得分:0)

您需要添加

resultvideo.setVideoURI(videoUri);
在您初始化结果视频后