1

What I want is the same with Images. When the user clicks on a button (in my case the VideoView itself) I want to let them open the Gallery and load a video into the 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;
        }
    }

But nothing happens when I select the video in the Gallery. The Toast msg appears so I messed sg up with the Bundle or the Uri. It should be displayed in the VideoView, right?

erdomester
  • 11,789
  • 32
  • 132
  • 234

2 Answers2

0

After startactivity intent

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

it will work(I think so )

Robert
  • 5,278
  • 43
  • 65
  • 115
0

modify your onActivityResult method it will work.

@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;
           }
       }
vishal jangid
  • 2,967
  • 16
  • 22