Subversion Repositories sokoban

Rev

Blame | Last modification | View Log | RSS feed

  1. package gdi1sokoban.sound;
  2.  
  3. import gdi1sokoban.exceptions.InternalFailureException;
  4.  
  5. import java.util.HashMap;
  6.  
  7. /**
  8.  * SoundEngine class
  9.  *
  10.  * this class provides extended functionalities for handling
  11.  * sound output (asynchronous playing, sound loops, parallel sound output)
  12.  *
  13.  */
  14. public class SoundEngine {
  15.         public final static int SND_LOOP = 1;
  16.         public final static int SND_ASYNC = 2;
  17.         public final static int SND_SYNC = 0;
  18.         private final HashMap<String, SoundEntity> sndEntities = new HashMap<String, SoundEntity>(0);
  19.        
  20.         /**
  21.          * plays a sound file
  22.          * @param identifier identifier of the played sound, is used to control the sound's behaviour at a later time
  23.          * @param fileName filename of the sound
  24.          * @param sndOptions output options (SND_LOOP = loop sound, SND_ASYNC = play sound asynchronously, SND_SYNC = play sound sychronously)
  25.          * @throws InternalFailureException
  26.          */
  27.         public void playSound(final String identifier, final String fileName, final int sndOptions) throws InternalFailureException {
  28.                 if (sndEntities.get(identifier) != null)
  29.                         stopSound(identifier);
  30.                 sndEntities.put(identifier, new SoundEntity());
  31.                 sndEntities.get(identifier).playSound(fileName, sndOptions);
  32.         }
  33.        
  34.         /**
  35.          * stops a sound
  36.          * @param identifier identifier of the sound
  37.          */
  38.         public void stopSound(final String identifier) {
  39.                 if ( (sndEntities.get(identifier) == null) )
  40.                         return;
  41.                 if (! sndEntities.get(identifier).hasStopped())
  42.                         sndEntities.get(identifier).stopSound();
  43.                 sndEntities.remove(identifier);
  44.         }
  45. }
  46.