Archive for January 4th, 2008
Resolved Question: Playing mp3 in Java Applications?
I don't know how to get an mp3 file to play in Java applications. The code I'm using is below:
import sun.audio.*; //import the sun.audio package
import java.io.*;
//** add this into your application code as appropriate
// Open an input stream to the audio file.
public class MP3
{
public static void main (String [] args) throws IOException
{
InputStream in = new FileInputStream("Runaway.mp3");
// Create an AudioStream object from the input stream.
AudioStream as = new AudioStream(in);
// Use the static class member "player" from class AudioPlayer to play
// clip.
AudioPlayer.player.start(as);
// Similarly, to stop the audio.
AudioPlayer.player.stop(as);
}
}
This is the error message I'm getting:
IOException: could not create audio stream from input stream
at sun.audio.AudioStream.(Unknown Source)
at MP3.main(MP3.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.ref
