use of android.media.MediaMetadataRetriever in project android_packages_apps_Camera by CyanogenMod.
the class Thumbnail method createVideoThumbnailBitmap.
private static Bitmap createVideoThumbnailBitmap(String filePath, FileDescriptor fd, int targetWidth) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
if (filePath != null) {
retriever.setDataSource(filePath);
} else {
retriever.setDataSource(fd);
}
bitmap = retriever.getFrameAtTime(-1);
} catch (IllegalArgumentException ex) {
// Assume this is a corrupt video file
} catch (RuntimeException ex) {
// Assume this is a corrupt video file.
} finally {
try {
retriever.release();
} catch (RuntimeException ex) {
// Ignore failures while cleaning up.
}
}
if (bitmap == null)
return null;
// Scale down the bitmap if it is bigger than we need.
int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width > targetWidth) {
float scale = (float) targetWidth / width;
int w = Math.round(scale * width);
int h = Math.round(scale * height);
bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
}
return bitmap;
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by crdroidandroid.
the class MediaMetadataRetrieverTest method testThumbnailCapture.
// Test frame capture
@LargeTest
public static void testThumbnailCapture() throws Exception {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
boolean supportWMA = MediaProfileReader.getWMAEnable();
boolean supportWMV = MediaProfileReader.getWMVEnable();
boolean hasFailed = false;
Log.v(TAG, "Thumbnail processing starts");
long startedAt = System.currentTimeMillis();
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]);
Bitmap bitmap = retriever.getFrameAtTime(-1);
assertTrue(bitmap != null);
try {
java.io.OutputStream stream = new FileOutputStream(MediaNames.THUMBNAIL_METADATA_TEST_FILES[i] + ".jpg");
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
stream.close();
} catch (Exception e) {
Log.e(TAG, "Fails to convert the bitmap to a JPEG file for " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
hasFailed = true;
Log.e(TAG, e.toString());
}
} 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();
}
long endedAt = System.currentTimeMillis();
retriever.release();
assertTrue(!hasFailed);
Log.v(TAG, "Average processing time per thumbnail: " + (endedAt - startedAt) / MediaNames.THUMBNAIL_METADATA_TEST_FILES.length + " ms");
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by crdroidandroid.
the class MediaMetadataRetrieverTest method testGetEmbeddedPicture.
// Test album art extraction.
@MediumTest
public static void testGetEmbeddedPicture() throws Exception {
Log.v(TAG, "testGetEmbeddedPicture starts.");
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
boolean supportWMA = MediaProfileReader.getWMAEnable();
boolean hasFailed = false;
boolean supportWMV = MediaProfileReader.getWMVEnable();
for (int i = 0, n = MediaNames.ALBUMART_TEST_FILES.length; i < n; ++i) {
try {
Log.v(TAG, "File " + i + ": " + MediaNames.ALBUMART_TEST_FILES[i]);
if ((MediaNames.ALBUMART_TEST_FILES[i].endsWith(".wma") && !supportWMA) || (MediaNames.ALBUMART_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.ALBUMART_TEST_FILES[i]);
byte[] albumArt = retriever.getEmbeddedPicture();
// known result.
if (albumArt == null) {
// Do we have expect in JUnit?
Log.e(TAG, "Fails to get embedded picture for " + MediaNames.ALBUMART_TEST_FILES[i]);
hasFailed = true;
}
} catch (Exception e) {
Log.e(TAG, "Fails to setDataSource for " + MediaNames.ALBUMART_TEST_FILES[i]);
hasFailed = true;
}
// Don't be evil
Thread.yield();
}
retriever.release();
Log.v(TAG, "testGetEmbeddedPicture completes.");
assertTrue(!hasFailed);
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by crdroidandroid.
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 android_frameworks_base by crdroidandroid.
the class MediaMetadataRetrieverTest method testBasicAbnormalMethodCallSequence.
// If setDataSource() has not been called, both getFrameAtTime() and extractMetadata() must
// return null.
@MediumTest
public static void testBasicAbnormalMethodCallSequence() {
boolean hasFailed = false;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
if (retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM) != null) {
Log.e(TAG, "No album metadata expected, but is available");
hasFailed = true;
}
if (retriever.getFrameAtTime(-1) != null) {
Log.e(TAG, "No frame expected, but is available");
hasFailed = true;
}
assertTrue(!hasFailed);
}
Aggregations