2013-07-21 60 views
1

我想要的與圖像相同。當用戶點擊一個按鈕(在我的情況下VideoView本身),我想讓他們打開圖庫並將視頻加載到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; 
     } 
    } 

但是,當我在圖庫中選擇視頻時沒有任何反應。敬酒信息出現了,所以我搞砸了捆綁或Uri。它應該顯示在VideoView中,對嗎?

回答

0

意圖startactivity

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

,將工作(我是這麼認爲的)

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; 
      } 
     }