MiloDC
asked on
Playing MP3 sound in a Java applet.
Anyone gotten JavaZOOM's MP3 SPI working?
Using their code example at http://www.javazoom.net/mp3spi/documents.html, and R.J. Lorimer's example at http://www.javalobby.org/java/forums/t18465.html (which is essentially the same thing), I can only play AIF and AU files. When I attempt to play an MP3, I get an error, "javax.sound.sampled.Unsup portedAudi oFileExcep tion: could not get audio input stream from input URL([path to audio file])."
The procedure in my code is:
private void mp3Play(URL urlMP3) {
try {
AudioInputStream audioIn = AudioSystem.getAudioInputS tream(urlM P3);
AudioFormat baseFormat = audioIn.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.En coding.PCM _SIGNED,
baseFormat.getSampleRate() ,
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate() ,
false);
AudioInputStream dataIn = AudioSystem.getAudioInputS tream(deco dedFormat, audioIn);
byte[] data = new byte[4096];
DataLine.Info info = new DataLine.Info(SourceDataLi ne.class, decodedFormat);
SourceDataLine line = null;
line = (SourceDataLine)AudioSyste m.getLine( info);
line.open(decodedFormat);
if (line != null) {
line.start();
int nBytesRead = 0, nBytesWritten = 0;
while (nBytesRead != -1) {
nBytesRead = dataIn.read(data, 0, data.length);
if (nBytesRead != -1)
nBytesWritten = line.write(data, 0, nBytesRead);
}
line.drain();
line.stop();
line.close();
dataIn.close();
}
audioIn.close();
} catch (Exception e) {
System.out.println("MP3 PLAYBACK ERROR: " + e.toString() + "(" + urlMP3.toString() + ")");
}
}
Again, this code works fine if I specify an AIF or AU file. I suspect that the format of the MP3 file that I'm trying to play is incompatible with the code, but I haven't tried encoding the sound differently, yet.
Help!
-- MiloDC
Using their code example at http://www.javazoom.net/mp3spi/documents.html, and R.J. Lorimer's example at http://www.javalobby.org/java/forums/t18465.html (which is essentially the same thing), I can only play AIF and AU files. When I attempt to play an MP3, I get an error, "javax.sound.sampled.Unsup
The procedure in my code is:
private void mp3Play(URL urlMP3) {
try {
AudioInputStream audioIn = AudioSystem.getAudioInputS
AudioFormat baseFormat = audioIn.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.En
baseFormat.getSampleRate()
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate()
false);
AudioInputStream dataIn = AudioSystem.getAudioInputS
byte[] data = new byte[4096];
DataLine.Info info = new DataLine.Info(SourceDataLi
SourceDataLine line = null;
line = (SourceDataLine)AudioSyste
line.open(decodedFormat);
if (line != null) {
line.start();
int nBytesRead = 0, nBytesWritten = 0;
while (nBytesRead != -1) {
nBytesRead = dataIn.read(data, 0, data.length);
if (nBytesRead != -1)
nBytesWritten = line.write(data, 0, nBytesRead);
}
line.drain();
line.stop();
line.close();
dataIn.close();
}
audioIn.close();
} catch (Exception e) {
System.out.println("MP3 PLAYBACK ERROR: " + e.toString() + "(" + urlMP3.toString() + ")");
}
}
Again, this code works fine if I specify an AIF or AU file. I suspect that the format of the MP3 file that I'm trying to play is incompatible with the code, but I haven't tried encoding the sound differently, yet.
Help!
-- MiloDC
how did u install the mp3 service provider?
ASKER
> Comment from objects
>
> how did u install the mp3 service provider?
Man, I just put jl1.0.jar, tritonus_share.jar, and mp3spi1.9.4.jar in my CLASSPATH. No further set-up is outlined on either of the two pages that I mentioned, above; is there more to installing the SPI than this? If so, is it going to be possible for me to employ the MP3 SPI in an applet?
-- MiloDC
>
> how did u install the mp3 service provider?
Man, I just put jl1.0.jar, tritonus_share.jar, and mp3spi1.9.4.jar in my CLASSPATH. No further set-up is outlined on either of the two pages that I mentioned, above; is there more to installing the SPI than this? If so, is it going to be possible for me to employ the MP3 SPI in an applet?
-- MiloDC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome, objects, that did it!
I just added ARCHIVE="jl1.0.jar,mp3spi1 .9.4.jar,t ritonus_sh are.jar" to the APPLET tag, and it worked.
Thanks!
-- MiloDC
I just added ARCHIVE="jl1.0.jar,mp3spi1
Thanks!
-- MiloDC
ASKER
-- MiloDC