[英]How to get all video from specific folder with path,duration and thumbnail using MediaStore?
[英]How to get a specific duration ( or less than that ) video paths using MediaStore
我可以使用MediaStore获取文件系统中所有视频的路径。 有没有任何方法可以使用MediaStore获得特定时长(或少于该时长)的视频。 例如视频时长少于15分钟。
这些是我获取视频路径的代码
public void getVideoPaths(Context context) {
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Video.VideoColumns.DATA};
Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
if (c != null) {
while (c.moveToNext()) {
filesNames.add(c.getString(0));
}
c.close();
}
}
String duration = Integer.toString(15*60*1000);
Cursor c = context.getContentResolver().query(uri, projection, MediaStore.Video.VideoColumns.DURATION + " < ?", new String[] {duration}, null);
这只会查询少于15分钟的文件
MediaStore是一个媒体提供程序,其中包含内部和外部存储设备上所有可用媒体的元数据。 您只需要拥有该视频文件的uri,就可以将以下代码用于持续时间
MediaPlayer mp = MediaPlayer.create(this, Uri.parse(uriOfYourFile));
int duration = mp.getDuration();
然后检查特定的持续时间。 您可以再使用一个选项,如下所述
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//use one of overloaded setDataSource() functions to set your data source
retriever.setDataSource(context, Uri.fromFile(videoFile));
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInMillisec = Long.parseLong(time );
retriever.release()
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.