use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.
the class MediaMetadataRetrieverTest method testMetadataRetrieval.
@LargeTest
public static void testMetadataRetrieval() throws Exception {
boolean supportWMA = MediaProfileReader.getWMAEnable();
boolean supportWMV = MediaProfileReader.getWMVEnable();
boolean hasFailed = false;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
for (int i = 0, n = MediaNames.THUMBNAIL_METADATA_TEST_FILES.length; i < n; ++i) {
try {
Log.v(TAG, "File " + i + ": " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
if ((MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wma") && !supportWMA) || (MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wmv") && !supportWMV)) {
Log.v(TAG, "windows media is not supported and thus we will skip the test for this file");
continue;
}
retriever.setDataSource(MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
extractAllSupportedMetadataValues(retriever);
} catch (Exception e) {
Log.e(TAG, "Fails to setDataSource for file " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
hasFailed = true;
}
// Don't be evil
Thread.yield();
}
retriever.release();
assertTrue(!hasFailed);
}
use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.
the class MediaDecoder method retrieveDefaultRotation.
@TargetApi(17)
private void retrieveDefaultRotation() {
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
metadataRetriever.setDataSource(mContext, mUri);
String rotationString = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
mDefaultRotation = rotationString == null ? 0 : Integer.parseInt(rotationString);
}
use of android.media.MediaMetadataRetriever in project Conversations by siacs.
the class FileBackend method getVideoPreview.
private Bitmap getVideoPreview(File file, int size) {
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
Bitmap frame;
try {
metadataRetriever.setDataSource(file.getAbsolutePath());
frame = metadataRetriever.getFrameAtTime(0);
metadataRetriever.release();
frame = resize(frame, size);
} catch (IllegalArgumentException | NullPointerException e) {
frame = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
frame.eraseColor(0xff000000);
}
drawOverlay(frame, R.drawable.play_video, 0.75f);
return frame;
}
use of android.media.MediaMetadataRetriever in project Timber by naman14.
the class TimberUtils method getAlbumArtForFile.
public static String getAlbumArtForFile(String filePath) {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(filePath);
return mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
}
use of android.media.MediaMetadataRetriever in project WordPress-Android by wordpress-mobile.
the class MediaUtils method getVideoDurationMS.
public static long getVideoDurationMS(Context context, Uri videoUri) {
if (context == null || videoUri == null) {
AppLog.e(AppLog.T.MEDIA, "context and videoUri can't be null.");
return 0L;
}
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(context, videoUri);
} catch (IllegalArgumentException | SecurityException e) {
AppLog.e(AppLog.T.MEDIA, "Can't read duration of the video.", e);
return 0L;
} catch (RuntimeException e) {
// Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/5431
AppLog.e(AppLog.T.MEDIA, "Can't read duration of the video due to a Runtime Exception happened setting the datasource", e);
return 0L;
}
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
if (time == null) {
return 0L;
}
return Long.parseLong(time);
}
Aggregations