Can you please suggest that how can i write a piece that plays a song.?
I tried the following snippet but i get the this exception:
import sun.audio.*;
import java.io.*;
class tester {
public static void main(String args[]) throws Exception {
InputStream in=new FileInputStream("tester.mp3");
AudioStream as=new AudioStream(in);
AudioPlayer.player.start(as);
}
}
As mentioned, Java Sound does not support MP3 by default. For the types it does support in any specific JRE, check
AudioSystem.getAudioFileTypes().One way to add support for reading MP3 is to add the JMF based mp3plugin.jar1 to the application’s run-time class-path.
As to your actual question, while a javax.sound.sampled.Clip might seem ideal for this kind of task, it unfortunately will only hold a second of stereo, 16 bit, 44.1KHz sound. That is why I developed
BigClip. (Which has its own problems with looping, if you fix them, report back.)