KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > media > format > audio > mpeg > TestMpegAudioHeader


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.test.media.format.audio.mpeg;
9
10 import java.io.File JavaDoc;
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 /**
24  * Test case for parsing MPEG Audio headers.
25  *
26  * @version <tt>$Revision: 1.1 $</tt>
27  * @author <a HREF="mailto:ogreen@users.sourceforge.net">Owen Green</a>
28  */

29 public class TestMpegAudioHeader extends TestCase
30 {
31    private static final Logger log =
32       Logger.getLogger(TestMpegAudioHeader.class);
33
34    private static final String JavaDoc RESOURCE_DIR = "media/format/data/";
35    private static final String JavaDoc MP3_FILE =
36       "jboss96k441khz_copyright_original.mp3";
37    private static final String JavaDoc MP3_MIME_TYPE = "audio/mpeg";
38
39    /**
40     * Constructor for TestMpegAudioHeader.
41     */

42    public TestMpegAudioHeader(String JavaDoc name)
43    {
44       super(name);
45    }
46
47    public void setUp() throws Exception JavaDoc
48    {
49       MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON;
50       mediaFormatRegistry.bind("mp3", new MpegAudioFormat());
51    }
52
53    public void tearDown() throws Exception JavaDoc
54    {
55       MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON;
56       mediaFormatRegistry.unbind("mp3");
57    }
58
59    public void testGetHeader() throws Exception JavaDoc
60    {
61       File JavaDoc 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 JavaDoc[] 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