package gdi1sokoban.sound;
import gdi1sokoban.exceptions.InternalFailureException;
import java.util.HashMap;
/**
* SoundEngine class
*
* this class provides extended functionalities for handling
* sound output (asynchronous playing, sound loops, parallel sound output)
*
*/
public class SoundEngine {
public final static int SND_LOOP = 1;
public final static int SND_ASYNC = 2;
public final static int SND_SYNC = 0;
/**
* plays a sound file
* @param identifier identifier of the played sound, is used to control the sound's behaviour at a later time
* @param fileName filename of the sound
* @param sndOptions output options (SND_LOOP = loop sound, SND_ASYNC = play sound asynchronously, SND_SYNC = play sound sychronously)
* @throws InternalFailureException
*/
public void playSound
(final String identifier,
final String fileName,
final int sndOptions
) throws InternalFailureException
{
if (sndEntities.get(identifier) != null)
stopSound(identifier);
sndEntities.put(identifier, new SoundEntity());
sndEntities.get(identifier).playSound(fileName, sndOptions);
}
/**
* stops a sound
* @param identifier identifier of the sound
*/
public void stopSound
(final String identifier
) {
if ( (sndEntities.get(identifier) == null) )
return;
if (! sndEntities.get(identifier).hasStopped())
sndEntities.get(identifier).stopSound();
sndEntities.remove(identifier);
}
}