vooga.gameEngine.controller
Class SoundController

java.lang.Object
  extended by vooga.gameEngine.controller.SoundController
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, AudioListener

public class SoundController
extends java.lang.Object
implements AudioListener, java.io.Serializable

GameRelatedItem can play sounds by adding this class as a listener. Developers can load in a Map to be used to reference audio files. These files will then be played when AudioEvents with corresponding map keys are fired from GameRelatedItems.

Supported audio file types include wav, aiff, au, mid, and rmf.

Author:
Geoffrey Lawler, Scott Brothers
See Also:
AudioListener, AudioEvent, Serialized Form

Constructor Summary
SoundController()
           
 
Method Summary
 void addAllToAudioMap(java.util.Map<java.lang.String,java.net.URL> audioMap)
          Provides support for adding a Map of Strings to URLs to this SoundController.
 void addToAudioMap(java.lang.String key, java.io.File value)
          Puts the specified key value pair in a map of Strings to audio files.
 void addToAudioMap(java.lang.String key, java.net.URL value)
          Puts the specified key value pair in a map of Strings to audio files.
 void audioRequested(AudioEvent e)
          This method retrieves and plays a sound based on the received AudioEvent.
 void pause()
          Pauses a background sound track.
 void playBackgroundSound(java.net.URL audioFile)
          Plays a sound located at the given File.
 void playClip(java.net.URL audioClipURL)
          Creates an audio clip from a URL and plays it.
 void resume()
          Resumes a paused background sound track.
 void setAudioMap(java.util.ResourceBundle bundle)
          Convenience method used to add built in support for ResourceBundles.
 void stopPlayback()
          Stops play back in the playing Thread which results in the termination of that Thread
 void togglePause()
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoundController

public SoundController()
Method Detail

addAllToAudioMap

public void addAllToAudioMap(java.util.Map<java.lang.String,java.net.URL> audioMap)
Provides support for adding a Map of Strings to URLs to this SoundController.

Parameters:
audioMap - Maps AudioEvent keys to files containing sounds.

setAudioMap

public void setAudioMap(java.util.ResourceBundle bundle)
Convenience method used to add built in support for ResourceBundles. Resource Bundles should be formatted with AudioEvent keys mapped to file names of the corresponding sounds. For ResourceBundle use all files MUST be local.

Parameters:
bundle - The properly formatted ResourceBundle

addToAudioMap

public void addToAudioMap(java.lang.String key,
                          java.net.URL value)
Puts the specified key value pair in a map of Strings to audio files.

Parameters:
key - Used to refer to an audio file via events or otherwise
value - a URL referring to a supported audio file.

addToAudioMap

public void addToAudioMap(java.lang.String key,
                          java.io.File value)
Puts the specified key value pair in a map of Strings to audio files.

Parameters:
key - Used to refer to an audio file via events or otherwise
value - a File referring to a supported audio file.

audioRequested

public void audioRequested(AudioEvent e)
Description copied from interface: AudioListener
This method retrieves and plays a sound based on the received AudioEvent.

Specified by:
audioRequested in interface AudioListener
Parameters:
e - The AudioEvent fired to request that a sound be played

playClip

public void playClip(java.net.URL audioClipURL)
Creates an audio clip from a URL and plays it. This method is best used for short audio clips.

Parameters:
audioClipURL - a URL mapping to the desired audio file.

playBackgroundSound

public void playBackgroundSound(java.net.URL audioFile)
Plays a sound located at the given File. Supported audio file types include wav, aiff, au, mid, and rmf. Sounds played through this method support pausing and larger file sizes than sounds played using the playClip(URL) method. Background sounds may be terminated by using the stopPlayback() method. Only one background sound may be played at a time. Calling this method when a background sound is playing will result in the current audio being terminated and replaced with the new audio.

Parameters:
audioFile - The File containing the audio file

togglePause

@Deprecated
public void togglePause()
Deprecated. 

Pauses or resumes background audio based on if it is active or not. This method is sometimes unreliable as it is possible to call this method before the audio buffer has cleared which can result in a game pause becoming out of synch with an audio pause. It is recommended to use the pause() method and resume() method.


pause

public void pause()
Pauses a background sound track.


resume

public void resume()
Resumes a paused background sound track.


stopPlayback

public void stopPlayback()
Stops play back in the playing Thread which results in the termination of that Thread