1 7 8 package org.jboss.test.media.format.audio.mpeg; 9 10 import java.io.File ; 11 12 import javax.emb.Media; 13 import javax.emb.MediaBean; 14 import javax.emb.MediaFormatRegistry; 15 16 import junit.framework.TestCase; 17 18 import org.jboss.logging.Logger; 19 import org.jboss.media.format.audio.mpeg.MpegAudioFormat; 20 import org.jboss.media.format.audio.mpeg.MpegAudioHeader; 21 import org.jboss.media.util.ResourceUtils; 22 23 29 public class TestMpegAudioHeader extends TestCase 30 { 31 private static final Logger log = 32 Logger.getLogger(TestMpegAudioHeader.class); 33 34 private static final String RESOURCE_DIR = "media/format/data/"; 35 private static final String MP3_FILE = 36 "jboss96k441khz_copyright_original.mp3"; 37 private static final String MP3_MIME_TYPE = "audio/mpeg"; 38 39 42 public TestMpegAudioHeader(String name) 43 { 44 super(name); 45 } 46 47 public void setUp() throws Exception 48 { 49 MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON; 50 mediaFormatRegistry.bind("mp3", new MpegAudioFormat()); 51 } 52 53 public void tearDown() throws Exception 54 { 55 MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON; 56 mediaFormatRegistry.unbind("mp3"); 57 } 58 59 public void testGetHeader() throws Exception 60 { 61 File file = ResourceUtils.getResourceFile(RESOURCE_DIR + MP3_FILE); 62 Media media = new MediaBean(file, MP3_MIME_TYPE); 63 MpegAudioHeader header = (MpegAudioHeader) media.getHeader(); 64 65 String [] fieldNames = header.getFieldNames(); 66 67 if (log.isDebugEnabled()) 68 { 69 for (int i = 0; i < fieldNames.length; i++) 70 { 71 System.out.println( 72 fieldNames[i] + ": " + header.getField(fieldNames[i])); 73 } 74 } 75 76 assertEquals("Original", true, header.isOriginal()); 77 assertEquals("Copyright", true, header.isCopyright()); 78 assertEquals("Bit Rate", 96, header.getBitrate()); 79 assertEquals("Sample Rate", 44100, header.getSamplerate()); 80 assertEquals( 81 "ChannelMode", 82 MpegAudioFormat.ChannelMode.JOINT_STEREO, 83 header.getChannelMode()); 84 assertEquals( 85 "Version", 86 MpegAudioFormat.Version.MPEG1, 87 header.getVersion()); 88 assertEquals("Layer", MpegAudioFormat.Layer.LAYERIII, header.getLayer()); 89 } 90 } | Popular Tags |