2014-05-24 78 views
-3

要求代碼訪問SD卡上的所有視頻文件,所有視頻文件....如何從SD卡到我的錄像機的應用程序訪問的Android

Mainvdo.java

public class Mainvdo extends Activity{ 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.video);  
     VideoView videoView = (VideoView)findViewById(R.id.videoView1); 
     MediaController mediaController = new MediaController(this); 
     mediaController.setAnchorView(videoView); 

     //Require code to access all video files on sd card.... 

     videoView.setMediaController(mediaController); 
     videoView.setVideoURI(uri); 
     videoView.requestFocus(); 
     videoView.start(); 
    } 
} 

回答

0

這會給你的路徑到SD卡上的所有視頻文件列表中

private void findAllVideoFiles() 
{  
    Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 
    String[] projection = { MediaStore.Video.VideoColumns.DATA, MediaStore.Video.VideoColumns.DISPLAY_NAME }; 
    Cursor videoCursor = getApplicationContext().getContentResolver().query(uri, projection, null, null, null); 

    if (videoCursor != null) { 
     while (videoCursor.moveToNext()) { 

      mediaNameList.add(videoCursor.getString(videoCursor.getColumnIndex(MediaStore.Video.VideoColumns.DISPLAY_NAME))); 
      mediaPathList.add(videoCursor.getString(0)); 
      //System.out.println("Video "+videoCursor.getString(videoCursor.getColumnIndex(MediaStore.Video.VideoColumns.DISPLAY_NAME))); 
     } 
     videoCursor.close(); 
    } 
} 
相關問題