1 7 8 package org.jboss.test.media.format.audio.oggvorbis; 9 10 import java.io.File ; 11 import java.util.Hashtable ; 12 import java.util.Vector ; 13 14 import javax.emb.Media; 15 import javax.emb.MediaBean; 16 import javax.emb.MediaFormatRegistry; 17 18 import junit.framework.TestCase; 19 20 import org.jboss.logging.Logger; 21 import org.jboss.media.format.audio.oggvorbis.OggVorbisFormat; 22 import org.jboss.media.format.audio.oggvorbis.OggVorbisHeader; 23 import org.jboss.media.util.ResourceUtils; 24 25 31 public class TestOggVorbisHeader extends TestCase 32 { 33 private static final Logger log = 34 Logger.getLogger(TestOggVorbisHeader.class); 35 36 private static String RESOURCE_DIRECTORY = "media/format/data/"; 37 private static final String OGG_VORBIS_FILE = "jboss48k16khz.ogg"; 38 private static final String OGG_VORBIS_MIME_TYPE = "application/ogg"; 39 40 43 public TestOggVorbisHeader(String name) 44 { 45 super(name); 46 } 47 48 public void setUp() throws Exception 49 { 50 MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON; 51 mediaFormatRegistry.bind("ogg", new OggVorbisFormat()); 52 } 53 54 public void tearDown() throws Exception 55 { 56 MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON; 57 mediaFormatRegistry.unbind("ogg"); 58 } 59 60 public void testGetHeaders() throws Exception 61 { 62 File file = 63 ResourceUtils.getResourceFile(RESOURCE_DIRECTORY + OGG_VORBIS_FILE); 64 Media media = new MediaBean(file, OGG_VORBIS_MIME_TYPE); 65 OggVorbisHeader header = (OggVorbisHeader) media.getHeader(); 66 67 String [] fieldNames = header.getFieldNames(); 68 69 if (log.isDebugEnabled()) 70 { 71 for (int i = 0; i < fieldNames.length; i++) 72 { 73 log.debug(fieldNames[i] + ": " + header.getField(fieldNames[i])); 74 } 75 } 76 77 assertEquals(new Integer (1), header.getField("channels")); 79 assertEquals(new Long (16000), header.getField("rate")); 80 assertEquals(new Long (48000), header.getField("bitRate")); 81 82 Hashtable comments = (Hashtable ) header.getField("comments"); 84 Vector tracknumber = (Vector ) comments.get("tracknumber"); 85 assertEquals("1", tracknumber.get(0)); 86 Vector date = (Vector ) comments.get("date"); 87 assertEquals("November 22 2003", date.get(0)); 88 Vector title = (Vector ) comments.get("title"); 89 assertEquals("JBoss Media Ogg Vorbis testing file.", title.get(0)); 90 } 91 } | Popular Tags |