at.tuwien.ifs.somtoolbox.audio
Class PlaybackThread

java.lang.Object
  extended by java.lang.Thread
      extended by at.tuwien.ifs.somtoolbox.audio.PlaybackThread
All Implemented Interfaces:
java.lang.Runnable

public class PlaybackThread
extends java.lang.Thread

Thread to play music files.

Version:
$Id: PlaybackThread.java 3590 2010-05-21 10:43:45Z mayer $
Author:
Ewald Peiszer

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  javax.sound.sampled.AudioInputStream[] audioInputStream
           
protected  byte[][] buffer
           
protected  byte[] datalineBuffer
           
static int decodedCount
           
static java.util.LinkedHashMap<java.io.File,java.io.File> decodedFiles
           
private  java.lang.String decodedOutputDir
           
static float DEFAULT_PROBABILITY_TO_DECODE
          Probability to decode a mp3 file to wav
(package private)  boolean[] empty
          Flag if channel is empty: in this case, there will be silence on the respective channel
protected  java.io.File file1
           
protected  java.io.File file2
           
(package private)  java.io.File[][] files
          Files to play
(package private)  java.lang.String id
           
protected  javax.sound.sampled.SourceDataLine line
           
protected  int monoFramesize
           
(package private)  boolean otherChannelAlreadyFinished
          (if bRepeat == false): if the first channel's musicfile stops, it is set to true.
If the second channel's musicfile stops, this thread is stopped.
private  java.util.Vector<PlaybackListener> playbackListeners
           
(package private)  java.awt.Point[] positions
           
(package private)  float probalityToDecode
           
protected  boolean quitLoop
           
static java.util.Random rand
           
protected  boolean ready
           
(package private)  boolean repeatShuffle
          Flag: if true, then music is played endlessly, alwas repeating.
static int songCount
           
private  boolean threadSuspended
           
(package private)  boolean updateStats
          Flag: if false, no global statistic variable will be updated by this Thread
(package private)  boolean[] waitForDecoder
          Flag: if true, then the respective channel is waiting for a DecoderThread to finish.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
PlaybackThread(java.lang.String id, PlaybackThreadDataRecord record, javax.sound.sampled.SourceDataLine line, boolean repeat, float probalityToDecode, boolean updateStats, java.lang.String decodedOutputDir)
           
PlaybackThread(java.lang.String id, PlaybackThreadDataRecord record, javax.sound.sampled.SourceDataLine line, boolean repeat, float probalityToDecode, java.lang.String decodedOutputDir)
           
PlaybackThread(java.lang.String id, PlaybackThreadDataRecord record, javax.sound.sampled.SourceDataLine line, java.lang.String decodedOutputDir)
          Convenience constructur that takes a PlaybackThreadDataRecord and pulls all data from it to create a new thread.
Note the constructor call that looks quite crazy with all its necessary casts.
 
Method Summary
 boolean addPlaybackListener(PlaybackListener listener)
           
 void decodingFailed(int channel, boolean stats)
           
 void decodingFinished(java.io.File file, int channel, boolean stats, DecoderThread dt)
           
 javax.sound.sampled.AudioInputStream getNextSong(int channel, boolean stats)
           
 boolean isReady()
           
 void muteChannel(int channel)
           
 void pausePlayback()
           
 javax.sound.sampled.AudioInputStream prepareAudioInputStream(java.io.File file, int channel, boolean stats)
           
 boolean removePlaybackListener(PlaybackListener listener)
           
 void resumePlayback()
           
 void run()
           
 void stopPlayback()
           
 void unMuteChannel(int channel)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

decodedCount

public static int decodedCount

decodedFiles

public static java.util.LinkedHashMap<java.io.File,java.io.File> decodedFiles

DEFAULT_PROBABILITY_TO_DECODE

public static final float DEFAULT_PROBABILITY_TO_DECODE
Probability to decode a mp3 file to wav

See Also:
Constant Field Values

rand

public static java.util.Random rand

songCount

public static int songCount

audioInputStream

protected javax.sound.sampled.AudioInputStream[] audioInputStream

buffer

protected byte[][] buffer

datalineBuffer

protected byte[] datalineBuffer

decodedOutputDir

private java.lang.String decodedOutputDir

empty

boolean[] empty
Flag if channel is empty: in this case, there will be silence on the respective channel


file1

protected java.io.File file1

file2

protected java.io.File file2

files

java.io.File[][] files
Files to play


id

java.lang.String id

line

protected javax.sound.sampled.SourceDataLine line

monoFramesize

protected int monoFramesize

otherChannelAlreadyFinished

boolean otherChannelAlreadyFinished
(if bRepeat == false): if the first channel's musicfile stops, it is set to true.
If the second channel's musicfile stops, this thread is stopped.


playbackListeners

private java.util.Vector<PlaybackListener> playbackListeners

positions

java.awt.Point[] positions

probalityToDecode

float probalityToDecode

quitLoop

protected boolean quitLoop

ready

protected boolean ready

repeatShuffle

boolean repeatShuffle
Flag: if true, then music is played endlessly, alwas repeating. Songs are picked in random order.

If false, then on each channel there will be played each song in the list, from the first to the last, then exit.


threadSuspended

private boolean threadSuspended

updateStats

boolean updateStats
Flag: if false, no global statistic variable will be updated by this Thread


waitForDecoder

boolean[] waitForDecoder
Flag: if true, then the respective channel is waiting for a DecoderThread to finish.

Constructor Detail

PlaybackThread

public PlaybackThread(java.lang.String id,
                      PlaybackThreadDataRecord record,
                      javax.sound.sampled.SourceDataLine line,
                      boolean repeat,
                      float probalityToDecode,
                      boolean updateStats,
                      java.lang.String decodedOutputDir)

PlaybackThread

public PlaybackThread(java.lang.String id,
                      PlaybackThreadDataRecord record,
                      javax.sound.sampled.SourceDataLine line,
                      boolean repeat,
                      float probalityToDecode,
                      java.lang.String decodedOutputDir)

PlaybackThread

public PlaybackThread(java.lang.String id,
                      PlaybackThreadDataRecord record,
                      javax.sound.sampled.SourceDataLine line,
                      java.lang.String decodedOutputDir)
Convenience constructur that takes a PlaybackThreadDataRecord and pulls all data from it to create a new thread.
Note the constructor call that looks quite crazy with all its necessary casts.

Method Detail

addPlaybackListener

public boolean addPlaybackListener(PlaybackListener listener)

decodingFailed

public void decodingFailed(int channel,
                           boolean stats)

decodingFinished

public void decodingFinished(java.io.File file,
                             int channel,
                             boolean stats,
                             DecoderThread dt)

getNextSong

public javax.sound.sampled.AudioInputStream getNextSong(int channel,
                                                        boolean stats)
                                                 throws java.io.IOException,
                                                        javax.sound.sampled.UnsupportedAudioFileException
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException

isReady

public boolean isReady()

muteChannel

public void muteChannel(int channel)

pausePlayback

public void pausePlayback()

prepareAudioInputStream

public javax.sound.sampled.AudioInputStream prepareAudioInputStream(java.io.File file,
                                                                    int channel,
                                                                    boolean stats)
                                                             throws java.io.IOException,
                                                                    javax.sound.sampled.UnsupportedAudioFileException
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException

removePlaybackListener

public boolean removePlaybackListener(PlaybackListener listener)

resumePlayback

public void resumePlayback()

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

stopPlayback

public void stopPlayback()

unMuteChannel

public void unMuteChannel(int channel)