org.jrabbit.base.sound
Class Music

java.lang.Object
  extended by org.jrabbit.base.sound.Music

public class Music
extends java.lang.Object

Music is a convenience class that provides simple methods for managing a single, streaming loop of audio, with controls for looping, volume, and pitch. Basically, this class simplifies playing background music. For the most part, it offers methods that simply call other methods in Slick-Util's sound API, but it provides a single, simple, unified API.

Author:
Chris Molini

Field Summary
private static boolean looping
          Whether or not to loop the music.
private static org.newdawn.slick.openal.Audio music
          The currently loaded/playing music.
private static float pitch
          The current pitch setting.
private static float volume
          The current volume setting.
 
Constructor Summary
Music()
           
 
Method Summary
static void loop(java.lang.String filepath)
          Loops the indicated music file.
static float pitch()
          Learns the current music pitch.
static void play()
          Plays or loops the current music (if one has been already set).
static void play(boolean loop)
          Plays or loops the current music (if one has been already set).
static void play(Loader loader, boolean loop)
          Plays or loops the indicated music file.
static void play(java.lang.String filepath)
          Plays the indicated music file.
static void setPitch(float pitch)
          Sets the pitch of the currently playing music.
static void setVolume(float volume)
          Sets the volume of the currently playing music.
static void stop()
          Stops the current music playback, but remembers which music was playing.
static float volume()
          Learns the current music volume.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

music

private static org.newdawn.slick.openal.Audio music
The currently loaded/playing music.


volume

private static float volume
The current volume setting.


pitch

private static float pitch
The current pitch setting.


looping

private static boolean looping
Whether or not to loop the music.

Constructor Detail

Music

public Music()
Method Detail

loop

public static void loop(java.lang.String filepath)
Loops the indicated music file.

Parameters:
filepath - The resource location at which to find the desired sound file.

play

public static void play(java.lang.String filepath)
Plays the indicated music file.

Parameters:
filepath - The resource location at which to find the desired sound file.

play

public static void play(Loader loader,
                        boolean loop)
Plays or loops the indicated music file.

Parameters:
loader - The Loader pointing to the desired sound file.
loop - Whether or not to loop the music file.

play

public static void play(boolean loop)
Plays or loops the current music (if one has been already set). If it's already playing, this restarts it.

Parameters:
loop - Whether or not to loop the music.

play

public static void play()
Plays or loops the current music (if one has been already set). If it's already playing, this restarts it. NOTE: The music is looped based on whether or not the last played music was looping.


stop

public static void stop()
Stops the current music playback, but remembers which music was playing.


setVolume

public static void setVolume(float volume)
Sets the volume of the currently playing music.

Parameters:
volume - The new volume to set.

volume

public static float volume()
Learns the current music volume.

Returns:
The proportional value for how loud the music should be, compared to the source file. 1f = base volume, 2f = twice as loud, etc.

setPitch

public static void setPitch(float pitch)
Sets the pitch of the currently playing music.

Parameters:
pitch - The new pitch to set.

pitch

public static float pitch()
Learns the current music pitch.

Returns:
The value for how much the pitch should be multiplied. 1f = base pitch, 2f = 2x frequency, etc.