jfreerails.client.common
Class SoundManager

java.lang.Object
  extended by jfreerails.client.common.SoundManager
All Implemented Interfaces:
java.util.EventListener, javax.sound.sampled.LineListener, ModelRootListener

public class SoundManager
extends java.lang.Object
implements ModelRootListener, javax.sound.sampled.LineListener

This class is responsible for loading and playing sounds. Samples are read into a byte arrays so that they don't need to be loaded from disk each time they are played.

Author:
Luke

Nested Class Summary
private static class SoundManager.Sample
          Stores the audio data and properties of a sample.
 
Field Summary
private static java.util.logging.Logger logger
           
private  int maxLines
           
private  javax.sound.sampled.Mixer mixer
           
private  boolean playSounds
           
private  java.util.HashMap<java.lang.String,SoundManager.Sample> samples
           
private static SoundManager soundManager
           
private  java.util.LinkedList<javax.sound.sampled.Clip> voices
           
 
Constructor Summary
private SoundManager()
           
 
Method Summary
 void addClip(java.lang.String s)
           
static SoundManager getSoundManager()
           
private  java.io.ByteArrayInputStream loadStream(java.io.InputStream inputstream)
           
static void main(java.lang.String[] args)
           
 void playSound(java.lang.String s, int loops)
           
 void propertyChange(ModelRoot.Property p, java.lang.Object before, java.lang.Object after)
           
 void update(javax.sound.sampled.LineEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

soundManager

private static final SoundManager soundManager

maxLines

private int maxLines

mixer

private javax.sound.sampled.Mixer mixer

playSounds

private boolean playSounds

samples

private java.util.HashMap<java.lang.String,SoundManager.Sample> samples

voices

private final java.util.LinkedList<javax.sound.sampled.Clip> voices
Constructor Detail

SoundManager

private SoundManager()
Method Detail

getSoundManager

public static SoundManager getSoundManager()

main

public static void main(java.lang.String[] args)

addClip

public void addClip(java.lang.String s)
             throws java.io.IOException,
                    javax.sound.sampled.UnsupportedAudioFileException,
                    javax.sound.sampled.LineUnavailableException
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException
javax.sound.sampled.LineUnavailableException

loadStream

private java.io.ByteArrayInputStream loadStream(java.io.InputStream inputstream)
                                         throws java.io.IOException
Throws:
java.io.IOException

playSound

public void playSound(java.lang.String s,
                      int loops)

propertyChange

public void propertyChange(ModelRoot.Property p,
                           java.lang.Object before,
                           java.lang.Object after)
Specified by:
propertyChange in interface ModelRootListener

update

public void update(javax.sound.sampled.LineEvent event)
Specified by:
update in interface javax.sound.sampled.LineListener