com.realtime.crossfire.jxclient.sound
Class MusicManager

java.lang.Object
  extended by com.realtime.crossfire.jxclient.sound.MusicManager

public class MusicManager
extends java.lang.Object

Plays background music. At most one background music can be concurrently active (except for fading in/out effects).


Field Summary
private  AudioFileLoader audioFileLoader
          The AudioFileLoader for loading audio files.
private  DebugWriter debugSound
          The writer for logging sound related information or null to not log.
private  boolean enabled
          Whether background music is enabled.
private  boolean muted
          Whether background music is muted.
private  java.lang.String name
          The currently playing music name.
private  Processor processor
          The currently running processor, or null if none is active or if music is disabled.
private  java.lang.Thread thread
          The Thread executing processor.
 
Constructor Summary
MusicManager(AudioFileLoader audioFileLoader, DebugWriter debugSound)
          Creates a new instance.
 
Method Summary
 void play(java.lang.String name)
          Plays the given music.
private  void restart()
          Restarts the current music.
 void setEnabled(boolean enabled)
          Sets whether background music is enabled.
 void setMuted(boolean muted)
          Sets whether background music is muted.
 void shutdown()
          Terminates a playing background music and free resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

audioFileLoader

@NotNull
private final AudioFileLoader audioFileLoader
The AudioFileLoader for loading audio files.


debugSound

@Nullable
private final DebugWriter debugSound
The writer for logging sound related information or null to not log.


enabled

private boolean enabled
Whether background music is enabled. (User setting)


muted

private boolean muted
Whether background music is muted. (Depends on connection state)


name

@Nullable
private java.lang.String name
The currently playing music name. Set to null if no music is playing.


processor

@Nullable
private Processor processor
The currently running processor, or null if none is active or if music is disabled.


thread

@Nullable
private java.lang.Thread thread
The Thread executing processor. Set to null if none is executing.

Constructor Detail

MusicManager

public MusicManager(@NotNull
                    AudioFileLoader audioFileLoader,
                    @Nullable
                    DebugWriter debugSound)
Creates a new instance.

Parameters:
audioFileLoader - the audio file loader for loading audio files
debugSound - the writer for logging sound related information or null to not log
Method Detail

play

public void play(@Nullable
                 java.lang.String name)
Plays the given music. If the new music name is unchanged, continue playing.

Parameters:
name - the music name, or null to stop playing music

restart

private void restart()
Restarts the current music. Take into account enabled and muted settings.


setEnabled

public void setEnabled(boolean enabled)
Sets whether background music is enabled.

Parameters:
enabled - whether background music is enabled

setMuted

public void setMuted(boolean muted)
Sets whether background music is muted.

Parameters:
muted - whether background music is muted

shutdown

public void shutdown()
Terminates a playing background music and free resources.