org.newdawn.slick
Class Music

java.lang.Object
  extended by org.newdawn.slick.Music

public class Music
extends java.lang.Object

A piece of music loaded and playable within the game. Only one piece of music can play at any given time and a channel is reserved so music will always play.

Author:
kevin, Nathan Sweet

Constructor Summary
Music(java.io.InputStream in, java.lang.String ref)
          Create and load a piece of music (either OGG or MOD/XM)
Music(java.lang.String ref)
          Create and load a piece of music (either OGG or MOD/XM)
Music(java.lang.String ref, boolean streamingHint)
          Create and load a piece of music (either OGG or MOD/XM)
Music(java.net.URL ref)
          Create and load a piece of music (either OGG or MOD/XM)
Music(java.net.URL url, boolean streamingHint)
          Create and load a piece of music (either OGG or MOD/XM)
 
Method Summary
 void addListener(MusicListener listener)
          Add a listener to this music
 void fade(int duration, float endVolume, boolean stopAfterFade)
          Fade this music to the volume specified
 float getPosition()
          The position into the sound thats being played
 float getVolume()
          Get the individual volume of the music
 void loop()
          Loop the music
 void loop(float pitch, float volume)
          Loop the music at a given pitch and volume
 void pause()
          Pause the music playback
 void play()
          Play the music
 void play(float pitch, float volume)
          Play the music at a given pitch and volume
 boolean playing()
          Check if the music is being played
static void poll(int delta)
          Poll the state of the current music.
 void removeListener(MusicListener listener)
          Remove a listener from this music
 void resume()
          Resume the music playback
 boolean setPosition(float position)
          Seeks to a position in the music.
 void setVolume(float volume)
          Set the volume of the music as a factor of the global volume setting
 void stop()
          Stop the music playing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Music

public Music(java.lang.String ref)
      throws SlickException
Create and load a piece of music (either OGG or MOD/XM)

Parameters:
ref - The location of the music
Throws:
SlickException

Music

public Music(java.net.URL ref)
      throws SlickException
Create and load a piece of music (either OGG or MOD/XM)

Parameters:
ref - The location of the music
Throws:
SlickException

Music

public Music(java.io.InputStream in,
             java.lang.String ref)
      throws SlickException
Create and load a piece of music (either OGG or MOD/XM)

Parameters:
in - The stream to read the music from
ref - The symbolic name of this music
Throws:
SlickException - Indicates a failure to read the music from the stream

Music

public Music(java.net.URL url,
             boolean streamingHint)
      throws SlickException
Create and load a piece of music (either OGG or MOD/XM)

Parameters:
url - The location of the music
streamingHint - A hint to indicate whether streaming should be used if possible
Throws:
SlickException

Music

public Music(java.lang.String ref,
             boolean streamingHint)
      throws SlickException
Create and load a piece of music (either OGG or MOD/XM)

Parameters:
ref - The location of the music
streamingHint - A hint to indicate whether streaming should be used if possible
Throws:
SlickException
Method Detail

poll

public static void poll(int delta)
Poll the state of the current music. This causes streaming music to stream and checks listeners. Note that if you're using a game container this will be auto-magically called for you.

Parameters:
delta - The amount of time since last poll

addListener

public void addListener(MusicListener listener)
Add a listener to this music

Parameters:
listener - The listener to add

removeListener

public void removeListener(MusicListener listener)
Remove a listener from this music

Parameters:
listener - The listener to remove

loop

public void loop()
Loop the music


play

public void play()
Play the music


play

public void play(float pitch,
                 float volume)
Play the music at a given pitch and volume

Parameters:
pitch - The pitch to play the music at (1.0 = default)
volume - The volume to play the music at (1.0 = default)

loop

public void loop(float pitch,
                 float volume)
Loop the music at a given pitch and volume

Parameters:
pitch - The pitch to play the music at (1.0 = default)
volume - The volume to play the music at (1.0 = default)

pause

public void pause()
Pause the music playback


stop

public void stop()
Stop the music playing


resume

public void resume()
Resume the music playback


playing

public boolean playing()
Check if the music is being played

Returns:
True if the music is being played

setVolume

public void setVolume(float volume)
Set the volume of the music as a factor of the global volume setting

Parameters:
volume - The volume to play music at. 0 - 1, 1 is Max

getVolume

public float getVolume()
Get the individual volume of the music

Returns:
The volume of this music, still effected by global SoundStore volume. 0 - 1, 1 is Max

fade

public void fade(int duration,
                 float endVolume,
                 boolean stopAfterFade)
Fade this music to the volume specified

Parameters:
duration - Fade time in milliseconds.
endVolume - The target volume
stopAfterFade - True if music should be stopped after fading in/out

setPosition

public boolean setPosition(float position)
Seeks to a position in the music. For streaming music, seeking before the current position causes the stream to be reloaded.

Parameters:
position - Position in seconds.
Returns:
True if the seek was successful

getPosition

public float getPosition()
The position into the sound thats being played

Returns:
The current position in seconds.


Copyright © 2006 New Dawn Software. All Rights Reserved.