2

Well, specifically, why this code here doesn't seem to want to play the second audio file:

public static void main(String[] args) {
    //Plays first file for a few seconds
    playMusic(new File("C:\\sample.wav"));
    wait(5.0);
    System.out.print("...");

    //Second file that doesn't want to play:
    playMusic(new File("C:\\sample2.wav"));
}

public static void playMusic(File Stream) {
    AudioInputStream AIS
    = AudioSystem.getAudioInputStream(Stream);

    Clip music = AudioSystem.getClip();
    music.open(AIS);
    music.start();
}

I figure I have to dismiss something or other (e.g. music.close(), AIS.close()), but these particular examples don't seem to have any effect. Any ideas?

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
Roberto C.
  • 75
  • 1
  • 8
  • For better help sooner, post an [SSCCE](http://pscode.org/sscce.html). For the sounds, either generate them in memory, or hot-link to ones available on the net. E.G. I provide some sounds through my [media page](http://pscode.org/media/#sound). – Andrew Thompson Sep 02 '11 at 03:04

1 Answers1

1

Is it possible your application terminates before your audio clip has finished playing? You may find this SO answer helpful.

Community
  • 1
  • 1
Jungle Hunter
  • 7,233
  • 11
  • 42
  • 67