tipgame.util
Class Sound

java.lang.Object
  extended by tipgame.util.Sound

public class Sound
extends java.lang.Object

This class handles playing, pausing, and muting sounds.

Author:
Jam Jenkins

Nested Class Summary
(package private) static class Sound.CurrentlyPlayingListener
          This class removes finished clips from the currentlyPlaying collection.
 
Field Summary
private static java.util.HashSet<javax.sound.sampled.Clip> currentlyPlaying
          the sounds not currently at the end position of the track
private static Sound.CurrentlyPlayingListener lineListener
          removes clips from currentlyPlaying when they finish
private static long muted
          determines if the advancing of sounds should be audible
private static boolean paused
          determines if the currently playing sounds should advance
private  java.net.URL soundFile
          the location of the sound file
private  java.util.LinkedList<javax.sound.sampled.Clip> sounds
          the sound clips cached (both playing and done playing)
 
Constructor Summary
Sound(java.net.URL soundFile)
          Makes a sound clip.
 
Method Summary
private static void advanceSounds(long millis)
          advances the time of the track while muted
private static boolean clipIsDone(javax.sound.sampled.Clip clip)
          determines if the clip is within 1 millisecond of finishing
private  javax.sound.sampled.Clip getClip()
          makes a new sound clip positioned at the end of the track
static void mute()
          makes the advancing of tracks not audible
static void pause()
          stops the current playing of the tracks in the current location
 void play()
          plays the sound clip, getting it from the cache of done playing clips if possible, making a new clip if all cached are currently playing
static void resume()
          resumes playing the tracks from their current location
static void turnSoundOn()
          makes the advancement of tracks audible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentlyPlaying

private static java.util.HashSet<javax.sound.sampled.Clip> currentlyPlaying
the sounds not currently at the end position of the track


sounds

private java.util.LinkedList<javax.sound.sampled.Clip> sounds
the sound clips cached (both playing and done playing)


soundFile

private java.net.URL soundFile
the location of the sound file


paused

private static boolean paused
determines if the currently playing sounds should advance


muted

private static long muted
determines if the advancing of sounds should be audible


lineListener

private static Sound.CurrentlyPlayingListener lineListener
removes clips from currentlyPlaying when they finish

Constructor Detail

Sound

public Sound(java.net.URL soundFile)
Makes a sound clip. The clip can be played repeatedly and does not need to finish before playing again.

Parameters:
soundFile - the url of the sound clip
Method Detail

getClip

private javax.sound.sampled.Clip getClip()
makes a new sound clip positioned at the end of the track

Returns:
the newly created sound clip

play

public void play()
plays the sound clip, getting it from the cache of done playing clips if possible, making a new clip if all cached are currently playing


clipIsDone

private static boolean clipIsDone(javax.sound.sampled.Clip clip)
determines if the clip is within 1 millisecond of finishing

Parameters:
clip - the clip to determine if it is done
Returns:
true if the clip is within 1 millisecond of finishing, false otherwise

pause

public static void pause()
stops the current playing of the tracks in the current location


resume

public static void resume()
resumes playing the tracks from their current location


mute

public static void mute()
makes the advancing of tracks not audible


advanceSounds

private static void advanceSounds(long millis)
advances the time of the track while muted

Parameters:
millis - the amount of time to advance in milliseconds

turnSoundOn

public static void turnSoundOn()
makes the advancement of tracks audible