1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.mediaframeworktest.functional; 18 19 import android.media.MediaMetadataRetriever; 20 import android.test.AndroidTestCase; 21 import android.test.suitebuilder.annotation.MediumTest; 22 import android.test.suitebuilder.annotation.Suppress; 23 import android.util.Log; 24 25 import com.android.mediaframeworktest.MediaNames; 26 import com.android.mediaframeworktest.MediaProfileReader; 27 /** 28 * This metadata test suite test the basic functionality of the 29 * MediaMetadataRetriever 30 * 31 */ 32 public class MediaMetadataTest extends AndroidTestCase { 33 34 private static final String TAG = "MediaMetadataTest"; 35 36 public static enum METADATA_EXPECTEDRESULT{ 37 FILE_PATH,CD_TRACK, ALBUM, 38 ARTIST, AUTHOR, COMPOSER, 39 DATE, GENRE, TITLE, 40 YEAR, DURATION, NUM_TRACKS, WRITER 41 } 42 43 public static enum MP3_TEST_FILE{ 44 ID3V1V2, ID3V2, ID3V1 45 } 46 47 public static METADATA_EXPECTEDRESULT meta; 48 public static MP3_TEST_FILE mp3_test_file; 49 50 @MediumTest 51 public static void testID3V1V2Metadata() throws Exception { 52 validateMetatData(mp3_test_file.ID3V1V2.ordinal(), MediaNames.META_DATA_MP3); 53 } 54 55 @MediumTest 56 public static void testID3V2Metadata() throws Exception { 57 validateMetatData(mp3_test_file.ID3V2.ordinal(), MediaNames.META_DATA_MP3); 58 } 59 60 @MediumTest 61 public static void testID3V1Metadata() throws Exception { 62 validateMetatData(mp3_test_file.ID3V1.ordinal(), MediaNames.META_DATA_MP3); 63 } 64 65 private static void validateMetatData(int fileIndex, String meta_data_file[][]) { 66 Log.v(TAG, "filePath = "+ meta_data_file[fileIndex][0]); 67 if ((meta_data_file[fileIndex][0].endsWith("wma") && !MediaProfileReader.getWMAEnable()) || 68 (meta_data_file[fileIndex][0].endsWith("wmv") && !MediaProfileReader.getWMVEnable())) { 69 return; 70 } 71 String value = null; 72 MediaMetadataRetriever retriever = new MediaMetadataRetriever(); 73 try { 74 retriever.setDataSource(meta_data_file[fileIndex][0]); 75 } catch(Exception e) { 76 Log.v(TAG, "Failed: "+meta_data_file[fileIndex][0] + " " + e.toString()); 77 //Set the test case failure whenever it failed to setDataSource 78 assertTrue("Failed to setDataSource ", false); 79 } 80 81 //METADATA_KEY_CD_TRACK_NUMBER should return the TCRK value 82 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER); 83 Log.v(TAG, "CD_TRACK_NUMBER : " + value); 84 assertEquals(TAG, meta_data_file[fileIndex][meta.CD_TRACK.ordinal()], value); 85 86 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); 87 Log.v(TAG, "Album : "+ value); 88 assertEquals(TAG, meta_data_file[fileIndex][meta.ALBUM.ordinal()], value); 89 90 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); 91 Log.v(TAG, "Artist : "+ value); 92 assertEquals(TAG, meta_data_file[fileIndex][meta.ARTIST.ordinal()], value); 93 94 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR); 95 Log.v(TAG, "Author : "+ value); 96 assertEquals(TAG, meta_data_file[fileIndex][meta.AUTHOR.ordinal()], value); 97 98 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER); 99 Log.v(TAG, "Composer : "+ value); 100 assertEquals(TAG, meta_data_file[fileIndex][meta.COMPOSER.ordinal()], value); 101 102 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE); 103 Log.v(TAG, "Date : "+ value); 104 assertEquals(TAG, meta_data_file[fileIndex][meta.DATE.ordinal()], value); 105 106 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE); 107 Log.v(TAG, "Genre : "+ value); 108 assertEquals(TAG, meta_data_file[fileIndex][meta.GENRE.ordinal()], value); 109 110 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); 111 Log.v(TAG, "Title : "+ value); 112 assertEquals(TAG, meta_data_file[fileIndex][meta.TITLE.ordinal()], value); 113 114 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); 115 Log.v(TAG, "Year : "+ value); 116 assertEquals(TAG, meta_data_file[fileIndex][meta.YEAR.ordinal()], value); 117 118 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); 119 Log.v(TAG, "Expected = " + meta_data_file[fileIndex][meta.DURATION.ordinal()] + "reult = " + value); 120 // Only require that the returned duration is within 100ms of the expected 121 // one as PV and stagefright differ slightly in their implementation. 122 assertTrue(TAG, Math.abs(Integer.parseInt( 123 meta_data_file[fileIndex][meta.DURATION.ordinal()]) 124 - Integer.parseInt(value)) < 100); 125 126 //METADATA_KEY_NUM_TRACKS should return the total number of tracks in the media 127 //include the video and audio 128 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS); 129 Log.v(TAG, "Track : "+ value); 130 assertEquals(TAG,meta_data_file[fileIndex][meta.NUM_TRACKS.ordinal()], value); 131 132 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER); 133 Log.v(TAG, "Writer : "+ value); 134 assertEquals(TAG,meta_data_file[fileIndex][meta.WRITER.ordinal()], value); 135 136 retriever.release(); 137 } 138 } 139