0

This is my code

public static void main(String[] args) {
    try{
        // open the sound file as a Java input stream
        InputStream in = new FileInputStream("Sound.wav");

        // create an audiostream from the inputstream
        AudioStream audioStream = new AudioStream(in);

        // play the audio clip with the audioplayer class
        AudioPlayer.player.start(audioStream); 
    }
    catch(Exception e){
        System.out.println("Audio not found");
    }
}
eebbesen
  • 5,070
  • 8
  • 48
  • 70
Annonymous177
  • 563
  • 2
  • 10
  • 21
  • 1
    possible duplicate of [Music Loop in Java](http://stackoverflow.com/questions/4875080/music-loop-in-java) – Jabir Aug 03 '15 at 12:06
  • is there a limit on how big the wav file is cause i cant seem to play my file as it keep saying file not found – Annonymous177 Aug 03 '15 at 12:30

1 Answers1

0

Sun Audio is Undocumented

You should not be using Sun Audio in your program. See here and here.

The Answer Depends on Your Library

If you are using Java Clip (built-in), try the example here. This is probably the simplest method.

If you switch to use JavaFX, you can see the API here, which has ways to loop. However, JavaFX requires a bit of package restructuring, and there is a learning curve. Unless you need JavaFX for other reasons, I would avoid it.

If you are using any other library, please consult the API for that library, or share with us what you are attempting to use. I have personally used BasicPlayer, but it is quite old.

Community
  • 1
  • 1