我想要的与图像相同。当用户点击按钮(在我的情况下是VideoView本身)时,我想让他们打开图库并将视频加载到VideoView中。
vv_video = (VideoView) findViewById(R.id.vv_video);
vv_video.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), LOAD_VIDEO);
return false;
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
switch (requestCode) {
case LOAD_VIDEO:
Toast.makeText(NewBucketActivity.this, "test", Toast.LENGTH_SHORT).show(); //this appears!
Bundle video = data.getExtras();
mVideoCaptureUri = video.getParcelable("data");
vv_video.setVideoURI(mVideoCaptureUri);
break;
}
}
但是当我在图库中选择视频时没有任何反应。 Toast msg出现,所以我搞砸了Bundle或Uri。它应该显示在VideoView中,对吗?
答案 0 :(得分:0)
startactivity
意图之后
Uri mVideoURI = data.getData();
vv_video.setVideoURI(mVideoURI);
vv_video.start();
它会起作用(我想是的)
答案 1 :(得分:0)
修改你的onActivityResult方法。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
switch (requestCode) {
case LOAD_VIDEO:
Toast.makeText(Pdf.this, "test", Toast.LENGTH_SHORT).show(); //this appears!
// Bundle video = data.getData();
Uri mVideoCaptureUri = data.getData();
vv_video.setVideoURI(mVideoCaptureUri);
vv_video.start();
break;
}
}