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.%26lt;init%26gt;(Unknown Source)
at MP3.main(MP3.java:11)
at sun.reflect.NativeMethodAccessorImpl.inv... Method)
at sun.ref
Playing mp3 in Java Applications?small myspace
sun.audio.AudioPlayer is Sun proprietary API and may be removed in a future release. you try an open source mp3 library like :
http://www.cs.princeton.edu/introcs/faq/...
or java media frameworkd api (JMF Api) for this kind of works.
No comments:
Post a Comment