2013-12-11 34 views
2

該技術已成功執行,用於使用圖庫中的圖片 但我想爲音頻和視頻實現相同的功能。 代碼是如何從圖庫中選擇視頻並將所選視頻圖標設置爲ImageView

public void video(View v) 
{ 
    Intent i = new Intent(Intent.ACTION_PICK, 
      android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI); 
    RESULT_LOAD_VIDEO = 1; 
    startActivityForResult(i, RESULT_LOAD_VIDEO); 
} 
public void audio(View v) 
{ 
    Intent i = new Intent(Intent.ACTION_PICK, 
      android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); 
    RESULT_LOAD_AUDIO = 1; 
    startActivityForResult(i, RESULT_LOAD_AUDIO); 
} 

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



     if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK &&null != data) 
     { 
      Uri selectedImage = data.getData(); String[] 
     filePathColumn = { MediaStore.Images.Media.DATA }; 

     Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null); 
     cursor.moveToFirst(); 

     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String picturePath = cursor.getString(columnIndex); cursor.close(); 

     // String picturePath contains the path of selected Image 

     NewPoll.flag++; 
     Path.patha= picturePath; 
     Intent ints=new Intent(getApplicationContext(),NewPoll.class); 
     ints.putExtra("address",picturePath); 
     ints.putExtra("option",comingData); 
     startActivity(ints); 
     } 


     if (requestCode == RESULT_LOAD_VIDEO && resultCode == RESULT_OK &&null != data) 
     { 
      Uri selectedVideo= data.getData(); String[] 
     filePathColumn = { MediaStore.Video.Media.DATA }; 

     Cursor cursor = getContentResolver().query(selectedVideo,filePathColumn, null, null, null); 
     cursor.moveToFirst(); 

     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String videoPath = cursor.getString(columnIndex); cursor.close(); 

     // String picturePath contains the path of selected Image 

     NewPoll.flag++; 
     Path.patha= videoPath; 
     Intent ints=new Intent(getApplicationContext(),NewPoll.class); 
     ints.putExtra("address",videoPath); 
     ints.putExtra("option",comingData); 
     startActivity(ints); 
     } 




     if (requestCode == RESULT_LOAD_AUDIO && resultCode == RESULT_OK &&null != data) 
     { 
      Uri selectedAudio= data.getData(); String[] 
     filePathColumn = { MediaStore.Audio.Media.DATA }; 

     Cursor cursor = getContentResolver().query(selectedAudio,filePathColumn, null, null, null); 
     cursor.moveToFirst(); 

     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String audioPath = cursor.getString(columnIndex); cursor.close(); 

     // String picturePath contains the path of selected Image 

     NewPoll.flag++; 
     Path.patha= audioPath; 
     Intent ints=new Intent(getApplicationContext(),NewPoll.class); 
     ints.putExtra("address",audioPath); 
     ints.putExtra("option",comingData); 
     startActivity(ints); 
     } 

} 

我的照片庫成功,但不知道如何使用的視頻和音頻畫廊從烏爾側 守則appriciated! 謝謝

回答

0
//from this u get all audio 
    private void getallaudio() 
    { 

     String[] STAR = { "*" }; 


     Cursor audioCursor = ((Activity) cntx).managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, STAR, null, null, null); 
     if (audioCursor != null) 
     { 
      if (audioCursor.moveToFirst()) 
      { 
       do 
       { 

        String path = audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.DATA)); 
        controller.audioWrapper.add(new MediaWrapper(new File(path).getName(), path, "Audio",false,color_string)); 
//     Log.i("Audio Path",path); 
       }while (audioCursor.moveToNext()); 

      } 
//   audioCursor.close(); 
     } 
    } 

    //from this u get all video 
    private void getallvideo() 
    { 
     String[] STAR = { "*" }; 


     controller.videoWrapper.clear(); 
     Cursor videoCursor = ((Activity) cntx).managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, STAR, null, null, null); 
     if (videoCursor != null) 
     { 
      if (videoCursor.moveToFirst()) 
      { 
       do 
       { 


        String path = videoCursor.getString(videoCursor.getColumnIndex(MediaStore.Images.Media.DATA)); 
        controller.videoWrapper.add(new MediaWrapper(new File(path).getName(), path, "Video",false,color_string)); 
//     Log.i("Video Path",path); 
       }while (videoCursor.moveToNext()); 

      } 
//   videoCursor.close(); 
     } 
    } 
+0

什麼是控制器? –

+0

什麼是控制器? –

+0

只是忽略它實際上它是我的班級名稱,我保存這些數據你可以在任何地方保存你的數據 –

相關問題