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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top