1

我想要的与图像相同。当用户单击一个按钮(在我的情况下是 VideoView 本身)时,我想让他们打开 Gallery 并将视频加载到 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 出现了,所以我将 sg 与 Bundle 或 Uri 搞砸了。它应该显示在 VideoView 中,对吧?

4

2 回答 2

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;
           }
       }
于 2015-11-16T11:34:20.163 回答
0

startactivity意向后

Uri mVideoURI = data.getData();  
   vv_video.setVideoURI(mVideoURI);
    vv_video.start(); 

它会起作用(我想是的)

于 2015-11-16T10:48:04.193 回答