Add throws to MediaMetadataRetriever.release
Declare missing throws IOException. Bug: 200173116 Test: atest CtsMediaTestCases:MediaMetadataRetrieverTest Change-Id: I3d07391ca1dd90c3e7e05a7f95c9b65f58eb308c
This commit is contained in:
@@ -22804,7 +22804,7 @@ package android.media {
|
||||
|
||||
public class MediaMetadataRetriever implements java.lang.AutoCloseable {
|
||||
ctor public MediaMetadataRetriever();
|
||||
method public void close();
|
||||
method public void close() throws java.io.IOException;
|
||||
method @Nullable public String extractMetadata(int);
|
||||
method @Nullable public byte[] getEmbeddedPicture();
|
||||
method @Nullable public android.graphics.Bitmap getFrameAtIndex(int, @NonNull android.media.MediaMetadataRetriever.BitmapParams);
|
||||
@@ -22821,7 +22821,7 @@ package android.media {
|
||||
method @Nullable public android.graphics.Bitmap getPrimaryImage();
|
||||
method @Nullable public android.graphics.Bitmap getScaledFrameAtTime(long, int, @IntRange(from=1) int, @IntRange(from=1) int);
|
||||
method @Nullable public android.graphics.Bitmap getScaledFrameAtTime(long, int, @IntRange(from=1) int, @IntRange(from=1) int, @NonNull android.media.MediaMetadataRetriever.BitmapParams);
|
||||
method public void release();
|
||||
method public void release() throws java.io.IOException;
|
||||
method public void setDataSource(String) throws java.lang.IllegalArgumentException;
|
||||
method public void setDataSource(String, java.util.Map<java.lang.String,java.lang.String>) throws java.lang.IllegalArgumentException;
|
||||
method public void setDataSource(java.io.FileDescriptor, long, long) throws java.lang.IllegalArgumentException;
|
||||
|
||||
@@ -1073,16 +1073,24 @@ public class MediaMetadataRetriever implements AutoCloseable {
|
||||
@UnsupportedAppUsage
|
||||
private native byte[] getEmbeddedPicture(int pictureType);
|
||||
|
||||
/**
|
||||
* Releases any acquired resources. Call it when done with the object.
|
||||
*
|
||||
* @throws IOException When an {@link IOException} is thrown while closing a {@link
|
||||
* MediaDataSource} passed to {@link #setDataSource(MediaDataSource)}.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
public void close() throws IOException {
|
||||
release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call it when one is done with the object. This method releases the memory
|
||||
* allocated internally.
|
||||
* Releases any acquired resources. Call it when done with the object.
|
||||
*
|
||||
* @throws IOException When an {@link IOException} is thrown while closing a {@link
|
||||
* MediaDataSource} passed to {@link #setDataSource(MediaDataSource)}.
|
||||
*/
|
||||
public native void release();
|
||||
public native void release() throws IOException;
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||
private native void native_setup();
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||
|
||||
@@ -19,120 +19,138 @@ package com.android.mediaframeworktest.functional;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.test.suitebuilder.annotation.Suppress;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.mediaframeworktest.MediaNames;
|
||||
import com.android.mediaframeworktest.MediaProfileReader;
|
||||
/**
|
||||
* This metadata test suite test the basic functionality of the
|
||||
* MediaMetadataRetriever
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/** This metadata test suite test the basic functionality of the MediaMetadataRetriever */
|
||||
public class MediaMetadataTest extends AndroidTestCase {
|
||||
|
||||
|
||||
private static final String TAG = "MediaMetadataTest";
|
||||
|
||||
public static enum METADATA_EXPECTEDRESULT{
|
||||
FILE_PATH,CD_TRACK, ALBUM,
|
||||
ARTIST, AUTHOR, COMPOSER,
|
||||
DATE, GENRE, TITLE,
|
||||
YEAR, DURATION, NUM_TRACKS, WRITER
|
||||
public enum METADATA_EXPECTEDRESULT {
|
||||
FILE_PATH,
|
||||
CD_TRACK,
|
||||
ALBUM,
|
||||
ARTIST,
|
||||
AUTHOR,
|
||||
COMPOSER,
|
||||
DATE,
|
||||
GENRE,
|
||||
TITLE,
|
||||
YEAR,
|
||||
DURATION,
|
||||
NUM_TRACKS,
|
||||
WRITER
|
||||
}
|
||||
|
||||
public static enum MP3_TEST_FILE{
|
||||
ID3V1V2, ID3V2, ID3V1
|
||||
|
||||
public enum MP3_TEST_FILE {
|
||||
ID3V1V2,
|
||||
ID3V2,
|
||||
ID3V1
|
||||
}
|
||||
|
||||
|
||||
public static METADATA_EXPECTEDRESULT meta;
|
||||
public static MP3_TEST_FILE mp3_test_file;
|
||||
|
||||
|
||||
@MediumTest
|
||||
public static void testID3V1V2Metadata() throws Exception {
|
||||
validateMetatData(mp3_test_file.ID3V1V2.ordinal(), MediaNames.META_DATA_MP3);
|
||||
}
|
||||
|
||||
|
||||
@MediumTest
|
||||
public static void testID3V2Metadata() throws Exception {
|
||||
validateMetatData(mp3_test_file.ID3V2.ordinal(), MediaNames.META_DATA_MP3);
|
||||
}
|
||||
|
||||
|
||||
@MediumTest
|
||||
public static void testID3V1Metadata() throws Exception {
|
||||
validateMetatData(mp3_test_file.ID3V1.ordinal(), MediaNames.META_DATA_MP3);
|
||||
}
|
||||
|
||||
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())) {
|
||||
private static void validateMetatData(int fileIndex, String[][] metadataFile)
|
||||
throws IOException {
|
||||
Log.v(TAG, "filePath = " + metadataFile[fileIndex][0]);
|
||||
if ((metadataFile[fileIndex][0].endsWith("wma") && !MediaProfileReader.getWMAEnable())
|
||||
|| (metadataFile[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
|
||||
retriever.setDataSource(metadataFile[fileIndex][0]);
|
||||
} catch (Exception e) {
|
||||
Log.v(TAG, "Failed: " + metadataFile[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
|
||||
|
||||
// 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);
|
||||
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Album : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Artist : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Author : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Composer : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Date : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Genre : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Title : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
|
||||
Log.v(TAG, "Year : " + value);
|
||||
assertEquals(TAG, metadataFile[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);
|
||||
Log.v(
|
||||
TAG,
|
||||
"Expected = "
|
||||
+ metadataFile[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);
|
||||
int durationDifferenceMs =
|
||||
Math.abs(
|
||||
Integer.parseInt(metadataFile[fileIndex][meta.DURATION.ordinal()])
|
||||
- Integer.parseInt(value));
|
||||
assertTrue(TAG, durationDifferenceMs < 100);
|
||||
|
||||
retriever.release();
|
||||
// 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, metadataFile[fileIndex][meta.NUM_TRACKS.ordinal()], value);
|
||||
|
||||
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER);
|
||||
Log.v(TAG, "Writer : " + value);
|
||||
assertEquals(TAG, metadataFile[fileIndex][meta.WRITER.ordinal()], value);
|
||||
|
||||
retriever.release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,23 @@
|
||||
|
||||
package com.android.mediaframeworktest.unit;
|
||||
|
||||
import android.util.Log;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.graphics.Bitmap;
|
||||
import java.io.FileOutputStream;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.mediaframeworktest.MediaNames;
|
||||
import com.android.mediaframeworktest.MediaProfileReader;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
|
||||
private static final String TAG = "MediaMetadataRetrieverTest";
|
||||
|
||||
|
||||
private static final String TAG = "MediaMetadataRetrieverTest";
|
||||
|
||||
// Test album art extraction.
|
||||
@MediumTest
|
||||
public static void testGetEmbeddedPicture() throws Exception {
|
||||
@@ -40,10 +44,12 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
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");
|
||||
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]);
|
||||
@@ -52,15 +58,18 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
// TODO:
|
||||
// A better test would be to compare the retrieved album art with the
|
||||
// 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]);
|
||||
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) {
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Fails to setDataSource for " + MediaNames.ALBUMART_TEST_FILES[i]);
|
||||
hasFailed = true;
|
||||
}
|
||||
Thread.yield(); // Don't be evil
|
||||
Thread.yield(); // Don't be evil
|
||||
}
|
||||
retriever.release();
|
||||
Log.v(TAG, "testGetEmbeddedPicture completes.");
|
||||
@@ -76,61 +85,82 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
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) {
|
||||
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");
|
||||
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");
|
||||
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]);
|
||||
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]);
|
||||
} catch (Exception e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Fails to setDataSource for file "
|
||||
+ MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
|
||||
hasFailed = true;
|
||||
}
|
||||
Thread.yield(); // Don't be evil
|
||||
Thread.yield(); // Don't be evil
|
||||
}
|
||||
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");
|
||||
Log.v(
|
||||
TAG,
|
||||
"Average processing time per thumbnail: "
|
||||
+ (endedAt - startedAt) / MediaNames.THUMBNAIL_METADATA_TEST_FILES.length
|
||||
+ " ms");
|
||||
}
|
||||
|
||||
|
||||
@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) {
|
||||
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");
|
||||
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]);
|
||||
} catch (Exception e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Fails to setDataSource for file "
|
||||
+ MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
|
||||
hasFailed = true;
|
||||
}
|
||||
Thread.yield(); // Don't be evil
|
||||
Thread.yield(); // Don't be evil
|
||||
}
|
||||
retriever.release();
|
||||
assertTrue(!hasFailed);
|
||||
@@ -151,10 +181,12 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
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);
|
||||
throw new Exception(
|
||||
"Fails to convert the bitmap to a JPEG file for " + MediaNames.TEST_PATH_1,
|
||||
e);
|
||||
}
|
||||
extractAllSupportedMetadataValues(retriever);
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Fails to setDataSource for " + MediaNames.TEST_PATH_1, e);
|
||||
hasFailed = true;
|
||||
}
|
||||
@@ -181,7 +213,7 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
|
||||
// Test setDataSource()
|
||||
@MediumTest
|
||||
public static void testSetDataSource() {
|
||||
public static void testSetDataSource() throws IOException {
|
||||
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
||||
boolean hasFailed = false;
|
||||
|
||||
@@ -191,7 +223,7 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
retriever.setDataSource(path);
|
||||
Log.e(TAG, "IllegalArgumentException failed to be thrown.");
|
||||
hasFailed = true;
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof IllegalArgumentException)) {
|
||||
Log.e(TAG, "Expected a IllegalArgumentException, but got a different exception");
|
||||
hasFailed = true;
|
||||
@@ -203,7 +235,7 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
retriever.setDataSource(MediaNames.TEST_PATH_5);
|
||||
Log.e(TAG, "IllegalArgumentException failed to be thrown.");
|
||||
hasFailed = true;
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof IllegalArgumentException)) {
|
||||
Log.e(TAG, "Expected a IllegalArgumentException, but got a different exception");
|
||||
hasFailed = true;
|
||||
@@ -215,7 +247,7 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
retriever.setDataSource(MediaNames.TEST_PATH_4);
|
||||
Log.e(TAG, "RuntimeException failed to be thrown.");
|
||||
hasFailed = true;
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof RuntimeException)) {
|
||||
Log.e(TAG, "Expected a RuntimeException, but got a different exception");
|
||||
hasFailed = true;
|
||||
@@ -228,13 +260,13 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
retriever.setDataSource(MediaNames.TEST_PATH_3);
|
||||
Log.e(TAG, "RuntimeException failed to be thrown.");
|
||||
hasFailed = true;
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof RuntimeException)) {
|
||||
Log.e(TAG, "Expected a RuntimeException, but got a different exception");
|
||||
hasFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
retriever.release();
|
||||
assertTrue(!hasFailed);
|
||||
}
|
||||
@@ -244,17 +276,23 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase {
|
||||
// We should be able to compare the actual returned metadata with the expected metadata
|
||||
// with each given sample test file.
|
||||
private static void extractAllSupportedMetadataValues(MediaMetadataRetriever retriever) {
|
||||
String value = null;
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)) == null? "not found": value);
|
||||
Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR)) == null? "not found": value);
|
||||
int[] metadataRetrieverKeys =
|
||||
new int[] {
|
||||
MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER,
|
||||
MediaMetadataRetriever.METADATA_KEY_DURATION,
|
||||
MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS,
|
||||
MediaMetadataRetriever.METADATA_KEY_ALBUM,
|
||||
MediaMetadataRetriever.METADATA_KEY_ARTIST,
|
||||
MediaMetadataRetriever.METADATA_KEY_AUTHOR,
|
||||
MediaMetadataRetriever.METADATA_KEY_COMPOSER,
|
||||
MediaMetadataRetriever.METADATA_KEY_DATE,
|
||||
MediaMetadataRetriever.METADATA_KEY_GENRE,
|
||||
MediaMetadataRetriever.METADATA_KEY_TITLE,
|
||||
MediaMetadataRetriever.METADATA_KEY_YEAR
|
||||
};
|
||||
for (int metadataRetrieverKey : metadataRetrieverKeys) {
|
||||
String value = retriever.extractMetadata(metadataRetrieverKey);
|
||||
Log.v(TAG, value == null ? "not found" : value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,12 @@ import android.media.MediaMetadataRetriever;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.media.filterfw.FrameImage2D;
|
||||
import androidx.media.filterfw.FrameValue;
|
||||
import androidx.media.filterfw.RenderTarget;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@TargetApi(16)
|
||||
@@ -276,12 +278,13 @@ public class MediaDecoder implements
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
private void retrieveDefaultRotation() {
|
||||
private void retrieveDefaultRotation() throws IOException {
|
||||
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
|
||||
metadataRetriever.setDataSource(mContext, mUri);
|
||||
String rotationString = metadataRetriever.extractMetadata(
|
||||
MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
|
||||
mDefaultRotation = rotationString == null ? 0 : Integer.parseInt(rotationString);
|
||||
metadataRetriever.release();
|
||||
}
|
||||
|
||||
private void onStop(boolean notifyListener) {
|
||||
|
||||
Reference in New Issue
Block a user