FileDocCategorySizeDatePackage
MediaMetadataTest.javaAPI DocAndroid 5.1 API6172Thu Mar 12 22:22:30 GMT 2015com.android.mediaframeworktest.functional

MediaMetadataTest

public class MediaMetadataTest extends android.test.AndroidTestCase
This metadata test suite test the basic functionality of the MediaMetadataRetriever

Fields Summary
private static final String
TAG
public static METADATA_EXPECTEDRESULT
meta
public static MP3_TEST_FILE
mp3_test_file
Constructors Summary
Methods Summary
public static voidtestID3V1Metadata()

        validateMetatData(mp3_test_file.ID3V1.ordinal(), MediaNames.META_DATA_MP3);
    
public static voidtestID3V1V2Metadata()

   
    
          
        validateMetatData(mp3_test_file.ID3V1V2.ordinal(), MediaNames.META_DATA_MP3);
    
public static voidtestID3V2Metadata()

        validateMetatData(mp3_test_file.ID3V2.ordinal(), MediaNames.META_DATA_MP3);
    
private static voidvalidateMetatData(int fileIndex, java.lang.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();