greenfoot
Class GreenfootSound

java.lang.Object
  extended by greenfoot.GreenfootSound

public class GreenfootSound
extends java.lang.Object

Represents audio that can be played in Greenfoot. GreenfootSound represent one sound that can be played, stopped, looped etc. TODO: Midi (playback of a file to start with, maybe creation later) Add support for MP3, OGG etc What happens if playback is started from a static method? Should it depend on whether simulation is running? Should we allow playback if the simulation is not running? Probably not Do we need an isLooping() method? In general, should we have a lot of isXXX methods or only a few. Except for isStopped, the user could keep track of this himself. Do we need a close() to release resources (maybe not for now, can always be added later if needed)? Do we then need an open as well?

Version:
2.0
Author:
Poul Henriksen

Constructor Summary
GreenfootSound(java.lang.String filename)
          Creates a new sound from the given file.
 
Method Summary
 boolean isPaused()
          True if the sound is currently paused.
 boolean isPlaying()
          True if the sound is currently playing.
 boolean isStopped()
          True if the sound is currently stopped.
 void loop()
          Play this sound in a loop until it is explicitly stopped, or the current execution is stopped.
 void pause()
          Pauses the current playback of this sound.
 void play()
          Start playback of this sound.
 void stop()
          Stop playback of this sound if it is currently playing.
 java.lang.String toString()
          Returns a string representation of this sound.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GreenfootSound

public GreenfootSound(java.lang.String filename)
Creates a new sound from the given file. The following formats are supported: AIFF, AU and WAV.

Parameters:
filename - Typically the name of a file in the sounds directory in the project directory.
Method Detail

stop

public void stop()
Stop playback of this sound if it is currently playing. If the sound is played again later, it will start playing from the beginning. If the sound is currently paused it will now be stopped instead.


play

public void play()
Start playback of this sound. If it is playing already, it will do nothing. If the sound is currently looping, it will finish the current loop and stop. If the sound is currently paused, it will resume playback from the point where it was paused. The sound will be played once.


loop

public void loop()
Play this sound in a loop until it is explicitly stopped, or the current execution is stopped. If called on an already looping sound, it will do nothing. If the sound is already playing once, it will start looping instead. If the sound is currently paused, it will resume playback from the point where it was paused.


pause

public void pause()
Pauses the current playback of this sound. If the sound playback is started again later, it will resume from the point where it was paused. The resources for the sound will not be released until it is unpaused.


isPlaying

public boolean isPlaying()
True if the sound is currently playing.


isPaused

public boolean isPaused()
True if the sound is currently paused.


isStopped

public boolean isStopped()
True if the sound is currently stopped. This means that either stop() has been called or the sound has played to the end.


toString

public java.lang.String toString()
Returns a string representation of this sound.

Overrides:
toString in class java.lang.Object


Greenfoot homepage