我正在研究android中的視頻文件持續時間。但我無法得到它。我的視頻文件在SD卡中的特定文件夾中可用。想要將它們作爲列表視圖與持續時間和名稱進行綁定。我有這個名字。但是尋找解決方案來找到持續時間。請幫幫我 。提前致謝 。Android如何獲取特定文件夾中可用的視頻文件持續時間?
Rajesh。
我正在研究android中的視頻文件持續時間。但我無法得到它。我的視頻文件在SD卡中的特定文件夾中可用。想要將它們作爲列表視圖與持續時間和名稱進行綁定。我有這個名字。但是尋找解決方案來找到持續時間。請幫幫我 。提前致謝 。Android如何獲取特定文件夾中可用的視頻文件持續時間?
Rajesh。
int msec = MediaPlayer.create(context,Uri.fromFile(new File(path)))。getDuration();
不起作用。空指針異常 – vasanth 2016-01-08 13:02:19
不會創建MediaPlayer實例來獲取文件長度。在android中有一個專用的MediaMetadataRetriever類。更多詳細信息請訪問:http://stackoverflow.com/a/33247728/1713920 – 2016-03-16 17:44:22
您不需要創建MediaPlayer。我做了一個功能,它會給你的視頻文件存儲Android設備的持續時間。
public static long checkVideoDurationValidation(Context context, Uri uri){
Log.d("CommonHandler", "Uri: " + uri);
Cursor cursor = MediaStore.Video.query(context.getContentResolver(), uri, new
String[]{MediaStore.Video.VideoColumns.DURATION});
long duration = 0;
if (cursor != null && cursor.moveToFirst()) {
duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video
.VideoColumns.DURATION));
cursor.close();
}
return duration;
}
讓我知道你是否對此有任何疑問。
看到這可以幫助你http://stackoverflow.com/q/10883349/1289716 – MAC 2012-07-28 10:23:34
@ gtumca-MAC我已經試過,但沒有一個好的迴應形式,該代碼。 – RAJESH 2012-07-28 11:01:24