use of android.media.MediaMetadataRetriever in project android_frameworks_base by AOSPA.
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 AOSPA.
the class MediaMetadataTest method validateMetatData.
private static void validateMetatData(int fileIndex, String[][] meta_data_file) {
Log.v(TAG, "filePath = " + meta_data_file[fileIndex][0]);
if ((meta_data_file[fileIndex][0].endsWith("wma") && !MediaProfileReader.getWMAEnable()) || (meta_data_file[fileIndex][0].endsWith("wmv") && !MediaProfileReader.getWMVEnable())) {
return;
}
String value = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(meta_data_file[fileIndex][0]);
} catch (Exception e) {
Log.v(TAG, "Failed: " + meta_data_file[fileIndex][0] + " " + e.toString());
//Set the test case failure whenever it failed to setDataSource
assertTrue("Failed to setDataSource ", false);
}
//METADATA_KEY_CD_TRACK_NUMBER should return the TCRK value
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
Log.v(TAG, "CD_TRACK_NUMBER : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.CD_TRACK.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
Log.v(TAG, "Album : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.ALBUM.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
Log.v(TAG, "Artist : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.ARTIST.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR);
Log.v(TAG, "Author : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.AUTHOR.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
Log.v(TAG, "Composer : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.COMPOSER.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
Log.v(TAG, "Date : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.DATE.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
Log.v(TAG, "Genre : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.GENRE.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
Log.v(TAG, "Title : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.TITLE.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
Log.v(TAG, "Year : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.YEAR.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
Log.v(TAG, "Expected = " + meta_data_file[fileIndex][meta.DURATION.ordinal()] + "reult = " + value);
// Only require that the returned duration is within 100ms of the expected
// one as PV and stagefright differ slightly in their implementation.
assertTrue(TAG, Math.abs(Integer.parseInt(meta_data_file[fileIndex][meta.DURATION.ordinal()]) - Integer.parseInt(value)) < 100);
//METADATA_KEY_NUM_TRACKS should return the total number of tracks in the media
//include the video and audio
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS);
Log.v(TAG, "Track : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.NUM_TRACKS.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER);
Log.v(TAG, "Writer : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.WRITER.ordinal()], value);
retriever.release();
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by DirtyUnicorns.
the class MediaMetadataRetrieverTest method testBasicNormalMethodCallSequence.
// If the specified call order and valid media file is used, no exception
// should be thrown.
@MediumTest
public static void testBasicNormalMethodCallSequence() throws Exception {
boolean hasFailed = false;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(MediaNames.TEST_PATH_1);
Bitmap bitmap = retriever.getFrameAtTime(-1);
assertTrue(bitmap != null);
try {
java.io.OutputStream stream = new FileOutputStream("/sdcard/thumbnailout.jpg");
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
stream.close();
} catch (Exception e) {
throw new Exception("Fails to convert the bitmap to a JPEG file for " + MediaNames.TEST_PATH_1, e);
}
extractAllSupportedMetadataValues(retriever);
} catch (Exception e) {
Log.e(TAG, "Fails to setDataSource for " + MediaNames.TEST_PATH_1, e);
hasFailed = true;
}
retriever.release();
assertTrue(!hasFailed);
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by DirtyUnicorns.
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);
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by DirtyUnicorns.
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);
}
Aggregations