When the Android system starts, it scans the system files and scans the system-supported video files (mp4,3gp,wmv) into the Media Library (Mediastore), and the following code shows how to obtain the information for these files:
PublicStaticList<videoinfo> sysvideolist =NULL;Video information collection
Sysvideolist =NewArraylist<videoinfo> ();
Setvideolist ();
PrivatevoidSetvideolist () {
MediaStore.Video.Thumbnails.DATA: File path for video thumbnails
String[] Thumbcolumns = {MediaStore.Video.Thumbnails.DATA,
MediaStore.Video.Thumbnails.VIDEO_ID};
MediaStore.Video.Media.DATA: Video file path;
MediaStore.Video.Media.DISPLAY_NAME: Video file name, such as Testvideo.mp4
MediaStore.Video.Media.TITLE: video title: Testvideo
String[] Mediacolumns = {mediastore.video.media._id,
MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.MIME_TYPE,
MediaStore.Video.Media.DISPLAY_NAME};
cursor = Managedquery (MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
Mediacolumns,NULL,NULL,NULL);
if(cursor==NULL){
Toast.maketext (systemvideochooseactivity. This,"No playable video files found",1). Show ();
return;
}
if(Cursor.movetofirst ()) {
Do{
Videoinfo info =NewVideoinfo ();
intID = cursor.getint (cursor
. Getcolumnindex (mediastore.video.media._id));
Cursor thumbcursor = Managedquery (
MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
Thumbcolumns, MediaStore.Video.Thumbnails.VIDEO_ID
+"=" + ID,NULL,NULL);
if(Thumbcursor.movetofirst ()) {
Info.setthumbpath (Thumbcursor.getstring (thumbcursor
. Getcolumnindex (MediaStore.Video.Thumbnails.DATA)));
}
Info.setpath (cursor.getstring (cursor
. Getcolumnindexorthrow (MediaStore.Video.Media.DATA)));
Info.settitle (cursor.getstring (cursor
. Getcolumnindexorthrow (MediaStore.Video.Media.TITLE)));
Info.setdisplayname (cursor.getstring (cursor
. Getcolumnindexorthrow (MediaStore.Video.Media.DISPLAY_NAME)));
LogUtil.log (TAG,"DisplayName:" +info.getdisplayname ());
Info.setmimetype (cursor
. getString (cursor
. Getcolumnindexorthrow (MediaStore.Video.Media.MIME_TYPE)));
Sysvideolist.add (info);
} while (Cursor.movetonext ());
}
}
One thing to note: The system's Media Library does not automatically update after we add video files, how do we manually scan the media library, or restart the system to get updated video files from the Media Library:
Sendbroadcast (New Intent (intent.action_media_mounted, Uri.parse ("file://"
+ environment.getexternalstoragedirectory ()));
How to scan a video file from the Android System Media Library