我将从原始视频加载所有视频并与媒体播放器一起显示

时间:2016-09-24 19:28:31

标签: android mediastore

我将从原始文件夹中加载所有视频并使用mediaplayr显示。为此使用以下代码但获得异常。怎么了? 感谢

String filePath = "android.resource://" + this.getPackageName() + "/raw/";
ContentResolver resolver=getContentResolver();
String projection[]=  {MediaStore.Video.Media._ID,MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.DURATION};
Cursor cursor= resolver.query(MediaStore.Video.Media.INTERNAL_CONTENT_URI ,projection, MediaStore.MediaColumns.DATA+ "='"+filePath+"'", null, null);

     videoDetails=new ArrayList<VideoInfo>();
     while(cursor.moveToNext())
     {
        int id=cursor.getInt(0);
        String title=cursor.getString(1);
        int dur=cursor.getInt(2);
        videoDetails.add(new VideoInfo(id,title,dur));

     }

1 个答案:

答案 0 :(得分:0)

您可以使用此功能播放原始视频

String  UrlPath="android.resource://"+getPackageName()+"/"+R.raw.ur_file_name;
videocontainer.setVideoURI(Uri.parse(UrlPath));
videocontainer.start();

代码来自主教Fakhry 来自how-to-play-videos-in-android-from-assets-folder-or-raw-folder