com.threerings.media.sound
Class SoundPlayer

java.lang.Object
  extended by com.threerings.media.sound.SoundPlayer
Direct Known Subclasses:
JavaSoundPlayer, OpenALSoundPlayer

public abstract class SoundPlayer
extends Object

Loads, plays and loops sounds.


Nested Class Summary
static interface SoundPlayer.Frob
          A control for sounds.
static class SoundPlayer.SoundType
          Create instances of this for your application to differentiate between different types of sounds.
 
Field Summary
protected  float _clipVol
          Volume level for sound clips.
protected  Set<SoundPlayer.SoundType> _disabledTypes
          A set of soundTypes for which sound is enabled.
protected  ObserverList<SoundEnabledObserver> _enabledObservers
           
static SoundPlayer.SoundType DEFAULT
          The default sound type.
static float PAN_CENTER
          A pan value indicating that a sound should play from center.
static float PAN_LEFT
          A pan value indicating that a sound should play from the left only.
static float PAN_RIGHT
          A pan value indicating that a sound should play from the right only.
 
Constructor Summary
SoundPlayer()
           
 
Method Summary
 void addSoundEnabledObserver(SoundEnabledObserver listener)
           
 float getClipVolume()
          Get the volume for all sound clips.
protected abstract  RunQueue getSoundQueue()
          Gets the run queue on which sound should be played.
 boolean isEnabled(SoundPlayer.SoundType type)
          Is the specified soundtype enabled?
abstract  void lock(String pkgPath, String... keys)
          Optionally lock each of these keys prior to playing, to guarantee that it will be quickly available for playing.
 SoundPlayer.Frob loop(SoundPlayer.SoundType type, String pkgPath, String key)
          Loop the specified sound, stopping as quickly as possible when stop is called.
 SoundPlayer.Frob loop(SoundPlayer.SoundType type, String pkgPath, String key, float pan)
          Loop the specified sound, stopping as quickly as possible when stop is called.
protected abstract  SoundPlayer.Frob loop(String pkgPath, String key, float pan)
          Loop the specified sound, stopping as quickly as possible when stop is called.
 boolean play(SoundPlayer.SoundType type, String pkgPath, String key)
          Play the specified sound as the specified type of sound, immediately.
 boolean play(SoundPlayer.SoundType type, String pkgPath, String key, float pan)
          Play the specified sound as the specified type of sound, immediately, with the specified pan value.
 boolean play(SoundPlayer.SoundType type, String pkgPath, String key, int delay)
          Play the specified sound after the specified delay.
 boolean play(SoundPlayer.SoundType type, String pkgPath, String key, int delay, float pan)
          Play the specified sound after the specified delay.
protected abstract  void play(String pkgPath, String key, float pan)
          Play the specified sound after the specified delay.
 void removeSoundEnabledObserver(SoundEnabledObserver listener)
           
 void setClipVolume(float vol)
          Sets the volume for all sound clips.
 void setEnabled(SoundPlayer.SoundType type, boolean enabled)
          Turns on or off the specified sound type.
 boolean shouldPlay(SoundPlayer.SoundType type)
          Is sound on and is the specified soundtype enabled?
abstract  void shutdown()
          Shut the damn thing off.
 String summarizeState()
          Returns a string summarizing our volume settings and disabled sound types.
abstract  void unlock(String pkgPath, String... keys)
          Unlock the specified sounds so that its resources can be freed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAN_LEFT

public static final float PAN_LEFT
A pan value indicating that a sound should play from the left only.

See Also:
Constant Field Values

PAN_RIGHT

public static final float PAN_RIGHT
A pan value indicating that a sound should play from the right only.

See Also:
Constant Field Values

PAN_CENTER

public static final float PAN_CENTER
A pan value indicating that a sound should play from center.

See Also:
Constant Field Values

DEFAULT

public static final SoundPlayer.SoundType DEFAULT
The default sound type.


_clipVol

protected float _clipVol
Volume level for sound clips.


_disabledTypes

protected Set<SoundPlayer.SoundType> _disabledTypes
A set of soundTypes for which sound is enabled.


_enabledObservers

protected ObserverList<SoundEnabledObserver> _enabledObservers
Constructor Detail

SoundPlayer

public SoundPlayer()
Method Detail

shutdown

public abstract void shutdown()
Shut the damn thing off.


summarizeState

public String summarizeState()
Returns a string summarizing our volume settings and disabled sound types.


isEnabled

public boolean isEnabled(SoundPlayer.SoundType type)
Is the specified soundtype enabled?


shouldPlay

public boolean shouldPlay(SoundPlayer.SoundType type)
Is sound on and is the specified soundtype enabled?


setEnabled

public void setEnabled(SoundPlayer.SoundType type,
                       boolean enabled)
Turns on or off the specified sound type.


addSoundEnabledObserver

public void addSoundEnabledObserver(SoundEnabledObserver listener)

removeSoundEnabledObserver

public void removeSoundEnabledObserver(SoundEnabledObserver listener)

setClipVolume

public void setClipVolume(float vol)
Sets the volume for all sound clips.

Parameters:
vol - a volume parameter between 0f and 1f, inclusive.

getClipVolume

public float getClipVolume()
Get the volume for all sound clips.


lock

public abstract void lock(String pkgPath,
                          String... keys)
Optionally lock each of these keys prior to playing, to guarantee that it will be quickly available for playing.


unlock

public abstract void unlock(String pkgPath,
                            String... keys)
Unlock the specified sounds so that its resources can be freed.


play

public boolean play(SoundPlayer.SoundType type,
                    String pkgPath,
                    String key)
Play the specified sound as the specified type of sound, immediately. Note that a sound need not be locked prior to playing.

Returns:
true if the sound actually played, or false if its sound type was disabled or if sound is off altogether.

play

public boolean play(SoundPlayer.SoundType type,
                    String pkgPath,
                    String key,
                    float pan)
Play the specified sound as the specified type of sound, immediately, with the specified pan value. Note that a sound need not be locked prior to playing.

Parameters:
pan - a value from -1f (all left) to +1f (all right).
Returns:
true if the sound actually played, or false if its sound type was disabled or if sound is off altogether.

play

public boolean play(SoundPlayer.SoundType type,
                    String pkgPath,
                    String key,
                    int delay)
Play the specified sound after the specified delay.

Parameters:
delay - the delay in milliseconds.
Returns:
true if the sound actually played, or false if its sound type was disabled or if sound is off altogether.

play

public boolean play(SoundPlayer.SoundType type,
                    String pkgPath,
                    String key,
                    int delay,
                    float pan)
Play the specified sound after the specified delay.

Parameters:
delay - the delay in milliseconds.
pan - a value from -1f (all left) to +1f (all right).
Returns:
true if the sound actually played, or false if its sound type was disabled or if sound is off altogether.

play

protected abstract void play(String pkgPath,
                             String key,
                             float pan)
Play the specified sound after the specified delay.

Parameters:
pan - a value from -1f (all left) to +1f (all right).

loop

public SoundPlayer.Frob loop(SoundPlayer.SoundType type,
                             String pkgPath,
                             String key)
Loop the specified sound, stopping as quickly as possible when stop is called.


loop

public SoundPlayer.Frob loop(SoundPlayer.SoundType type,
                             String pkgPath,
                             String key,
                             float pan)
Loop the specified sound, stopping as quickly as possible when stop is called.


loop

protected abstract SoundPlayer.Frob loop(String pkgPath,
                                         String key,
                                         float pan)
Loop the specified sound, stopping as quickly as possible when stop is called.


getSoundQueue

protected abstract RunQueue getSoundQueue()
Gets the run queue on which sound should be played. It defaults to RunQueue.AWT.