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:
Runnable

public class PlaybackThread
extends 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
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  AudioInputStream[] audioInputStream
           
protected  byte[][] buffer
           
protected  byte[] datalineBuffer
           
static int decodedCount
           
static LinkedHashMap<File,File> decodedFiles
           
private  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  File file1
           
protected  File file2
           
(package private)  File[][] files
          Files to play
(package private)  String id
           
protected  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  Vector<PlaybackListener> playbackListeners
           
(package private)  Point[] positions
           
(package private)  float probalityToDecode
           
protected  boolean quitLoop
           
static 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(String id, PlaybackThreadDataRecord record, SourceDataLine line, boolean repeat, float probalityToDecode, boolean updateStats, String decodedOutputDir)
           
PlaybackThread(String id, PlaybackThreadDataRecord record, SourceDataLine line, boolean repeat, float probalityToDecode, String decodedOutputDir)
           
PlaybackThread(String id, PlaybackThreadDataRecord record, SourceDataLine line, 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(File file, int channel, boolean stats, DecoderThread dt)
           
 AudioInputStream getNextSong(int channel, boolean stats)
           
 boolean isReady()
           
 void muteChannel(int channel)
           
 void pausePlayback()
           
 AudioInputStream prepareAudioInputStream(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 LinkedHashMap<File,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 Random rand

songCount

public static int songCount

audioInputStream

protected AudioInputStream[] audioInputStream

buffer

protected byte[][] buffer

datalineBuffer

protected byte[] datalineBuffer

decodedOutputDir

private String decodedOutputDir

empty

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


file1

protected File file1

file2

protected File file2

files

File[][] files
Files to play


id

String id

line

protected 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 Vector<PlaybackListener> playbackListeners

positions

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(String id,
                      PlaybackThreadDataRecord record,
                      SourceDataLine line,
                      boolean repeat,
                      float probalityToDecode,
                      boolean updateStats,
                      String decodedOutputDir)

PlaybackThread

public PlaybackThread(String id,
                      PlaybackThreadDataRecord record,
                      SourceDataLine line,
                      boolean repeat,
                      float probalityToDecode,
                      String decodedOutputDir)

PlaybackThread

public PlaybackThread(String id,
                      PlaybackThreadDataRecord record,
                      SourceDataLine line,
                      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(File file,
                             int channel,
                             boolean stats,
                             DecoderThread dt)

getNextSong

public AudioInputStream getNextSong(int channel,
                                    boolean stats)
                             throws IOException,
                                    UnsupportedAudioFileException
Throws:
IOException
UnsupportedAudioFileException

isReady

public boolean isReady()

muteChannel

public void muteChannel(int channel)

pausePlayback

public void pausePlayback()

prepareAudioInputStream

public AudioInputStream prepareAudioInputStream(File file,
                                                int channel,
                                                boolean stats)
                                         throws IOException,
                                                UnsupportedAudioFileException
Throws:
IOException
UnsupportedAudioFileException

removePlaybackListener

public boolean removePlaybackListener(PlaybackListener listener)

resumePlayback

public void resumePlayback()

run

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

stopPlayback

public void stopPlayback()

unMuteChannel

public void unMuteChannel(int channel)