diff options
author | ztenghui <ztenghui@google.com> | 2013-04-18 16:18:26 -0700 |
---|---|---|
committer | ztenghui <ztenghui@google.com> | 2013-04-18 16:21:43 -0700 |
commit | 91d28ba0b11060cf36c6b4750e53b887a5d1a193 (patch) | |
tree | f76671748ffdeafa578ef2c1f3dfe482cecaee2e /src/com/android/gallery3d | |
parent | e8b4b34cb77b179f397641e2f4572e4aa6be1943 (diff) | |
download | android_packages_apps_Gallery2-91d28ba0b11060cf36c6b4750e53b887a5d1a193.tar.gz android_packages_apps_Gallery2-91d28ba0b11060cf36c6b4750e53b887a5d1a193.tar.bz2 android_packages_apps_Gallery2-91d28ba0b11060cf36c6b4750e53b887a5d1a193.zip |
Update the duration information when saving new video
Change-Id: I9c3fd33dba7f04d9d905429c6bb17cf9a10b7628
Diffstat (limited to 'src/com/android/gallery3d')
-rw-r--r-- | src/com/android/gallery3d/util/SaveVideoFileUtils.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/com/android/gallery3d/util/SaveVideoFileUtils.java b/src/com/android/gallery3d/util/SaveVideoFileUtils.java index c281dd3e7..e2c5f51b9 100644 --- a/src/com/android/gallery3d/util/SaveVideoFileUtils.java +++ b/src/com/android/gallery3d/util/SaveVideoFileUtils.java @@ -19,6 +19,7 @@ package com.android.gallery3d.util; import android.content.ContentResolver; import android.content.ContentValues; import android.database.Cursor; +import android.media.MediaMetadataRetriever; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore.Video; @@ -95,7 +96,7 @@ public class SaveVideoFileUtils { ContentResolver contentResolver, Uri uri ) { long nowInMs = System.currentTimeMillis(); long nowInSec = nowInMs / 1000; - final ContentValues values = new ContentValues(12); + final ContentValues values = new ContentValues(13); values.put(Video.Media.TITLE, mDstFileInfo.mFileName); values.put(Video.Media.DISPLAY_NAME, mDstFileInfo.mFile.getName()); values.put(Video.Media.MIME_TYPE, "video/mp4"); @@ -104,6 +105,8 @@ public class SaveVideoFileUtils { values.put(Video.Media.DATE_ADDED, nowInSec); values.put(Video.Media.DATA, mDstFileInfo.mFile.getAbsolutePath()); values.put(Video.Media.SIZE, mDstFileInfo.mFile.length()); + int durationMs = retriveVideoDurationMs(mDstFileInfo.mFile.getPath()); + values.put(Video.Media.DURATION, durationMs); // Copy the data taken and location info from src. String[] projection = new String[] { VideoColumns.DATE_TAKEN, @@ -138,4 +141,18 @@ public class SaveVideoFileUtils { return contentResolver.insert(Video.Media.EXTERNAL_CONTENT_URI, values); } + public static int retriveVideoDurationMs(String path) { + int durationMs = 0; + // Calculate the duration of the destination file. + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + retriever.setDataSource(path); + String duration = retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_DURATION); + if (duration != null) { + durationMs = Integer.parseInt(duration); + } + retriever.release(); + return durationMs; + } + } |