Add EventHandler to AudioClip?


S

SimonSimon

Hello,

I have a java applet with a sound playing in the background. If I click
on a spot in the picture, another sound should play and the sound in
background should stop. I would like to play again this background
sound, when the second sound finishes playing. I hope I wrote clear
enough :)

This is my code:
clip1.loop();
.....
try{
clip1.stop();
}
catch(Exception e)
{
}
clip = applet.getAudioClip(applet.getCodeBase(), file);
clip.play();

If I'm correct, I would need an EventHandler for AudioClip, and this
EventHandler would lood for method stop(). Am I correct? How can I do
this?

Thanks,
Simon
 
Ad

Advertisements

O

Oliver Wong

SimonSimon said:
Hello,

I have a java applet with a sound playing in the background. If I click
on a spot in the picture, another sound should play and the sound in
background should stop. I would like to play again this background
sound, when the second sound finishes playing. I hope I wrote clear
enough :)

This is my code:
clip1.loop();
....
try{
clip1.stop();
}
catch(Exception e)
{
}
clip = applet.getAudioClip(applet.getCodeBase(), file);
clip.play();

If I'm correct, I would need an EventHandler for AudioClip, and this
EventHandler would lood for method stop(). Am I correct? How can I do
this?

AudioClip doesn't allow you to register listeners on it. Use the Clip
interface instead:

http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/sampled/Clip.html

- Oliver
 

Top