Search code examples
javaclip

What is the difference between AudioClip and Clip in java?


In my game I'm trying to add sfx and other sound elements. I used AudioClip for everything (BGM, sfx, etc). Now I would need to check if a sfx is already in loop or not. I would like to archieve that if the character is close to the portal a sfx should be played in loop. If its out of distance it should stop. I read that there is a .isRunning() function but it can be used only with Clip as far as I see. Here is a part of my code.

So what is the difference between AudioClip and Clip?

if (hero.getHeroX() > (MAZECOL - 5) * 30 && hero.getHeroY() > (MAZEROW - 4) * 30)
    if (portalSFX is not in loop)
        portalSFX.loop();
else
    portalSFX.stop();

Solution

  • AudioClip belongs to the applet API. There is really no point in using it. It is older and presents limited functionality.

    Clip belongs to javax.sound.sampled. It can be obtained from AudioSystem and there is an official tutorial here.