Package com.nerius.audio
Class ModernAudioClip
- java.lang.Object
-
- com.nerius.audio.ModernAudioClip
-
- All Implemented Interfaces:
AudioClip
public class ModernAudioClip extends java.lang.Object implements AudioClip
The implementation of this class uses Java 1.3 features, but nothing beyond that. In particular,AudioSystem.getClip()
is NOT used, that being a Java 1.5 feature.Instances of this class are completely thread safe, meaning that the five methods
play()
,loop()
,stop()
,pause()
, andresume()
can all be called by different threads, and can all be intertwined. All such calls [including construction] are safely placed onto an event dispatch queue and are handled sequentially by one thread.
-
-
Constructor Summary
Constructors Constructor Description ModernAudioClip(java.io.InputStream sndFile)
Construction actually takes place in a different thread; this constructs only a dummy container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
loop()
Plays the audio clip once through, then jumps back to beginning, playing it through again and again, indefinitely.void
pause()
Puts the audio clip into paused state, if not already.void
play()
Plays the audio clip once through.void
resume()
Resumes the clip after paused state, if clip was paused previously.void
stop()
Stops a playing or looping audio clip.
-
-
-
Constructor Detail
-
ModernAudioClip
public ModernAudioClip(java.io.InputStream sndFile)
Construction actually takes place in a different thread; this constructs only a dummy container. In case of errors during construction, the clip is disabled, and any further operations on this clip are ignored. Construction errors are printed toSystem.err
, but are not reported.The
sndFile
should havemarkSupported()
returntrue
.- Parameters:
sndFile
- AnInputStream
consisting of the contents of a WAV file (or AU file). Some other formats may work also, but I'm not sure which ones do. MP3 files certainly DON'T work.
-
-
Method Detail
-
play
public void play()
Description copied from interface:AudioClip
Plays the audio clip once through. This always causes the playing to start from beginning of clip, even in cases where clip is already playing or looping.
-
loop
public void loop()
Description copied from interface:AudioClip
Plays the audio clip once through, then jumps back to beginning, playing it through again and again, indefinitely. This always causes the playing to start from beginning of clip, even in cases where clip is already playing or looping.
-
stop
public void stop()
Description copied from interface:AudioClip
Stops a playing or looping audio clip. The next time the clip is played or looped it will start from beginning of clip.
-
pause
public void pause()
Description copied from interface:AudioClip
Puts the audio clip into paused state, if not already. When the clip is resumed it will continue exactly where it left off when it was paused. Ifplay()
,loop()
, orstop()
are called while the clip is paused, then uponresume()
the clip will behave as if calling those operations in the same order immediately upon resume.
-
resume
public void resume()
Description copied from interface:AudioClip
Resumes the clip after paused state, if clip was paused previously. For clarification on required behavior of pause/resume please see discussion onpause()
.- Specified by:
resume
in interfaceAudioClip
- See Also:
AudioClip.pause()
-
-