Add EventHandler to AudioClip?

Discussion in 'Java' started by SimonSimon, May 8, 2006.

  1. SimonSimon

    SimonSimon Guest

    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
     
    SimonSimon, May 8, 2006
    #1
    1. Advertisements

  2. SimonSimon

    Oliver Wong Guest

    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
     
    Oliver Wong, May 8, 2006
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.