从图库和Intent VideoView打开视频到新活动

时间:2017-03-03 11:04:47

标签: android video android-intent android-videoview android-video-player

我想制作从图库发布的视频播放器应用,并将视频播放到“新活动”。问题是,我已经在画廊浏览视频了。视频正在“主要活动”中播放,而不是在“新活动”中播放。请帮忙。

MainActivity:

public class MainActivity extends Activity {

Button button1;
VideoView videoView;
private static final int SELECT_VIDEO = 1;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button1 = (Button) findViewById(R.id.button1);
    videoView=(VideoView)findViewById(R.id.videoView);
    button1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent();
            intent.setType("video/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Video"), SELECT_VIDEO);

        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode != RESULT_OK) return;

    if (requestCode == SELECT_VIDEO) {
        Uri mVideoURI = data.getData();
        videoView.setVideoURI(mVideoURI);

        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        videoView.setMediaController(mediaController);

        videoView.start();

        }
    }
}

我应该在我的'new activity.java'中加入什么编码? 我也想把4个视频放在同一个活动中。我该怎么办?

1 个答案:

答案 0 :(得分:0)

将意图放在NewActivity中而不是MainActivity