/*
* Created on 2004/10/03
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.commons.audio;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
*
*
*/
public class ThreadJavaSoundAudioPlayer implements FileAudioPlayer,InputStreamAudioPlayer{
private JavaSoundAudioPlayer javaSoundAudioPlayer=new JavaSoundAudioPlayer();
private int v;
/* (non-Javadoc)
* @see org.jpn.xucker.commons.audio.sp.FileAudioPlayer#play(java.io.File)
*/
public void play(File file) {
try {
// TODO Auto-generated method stub
play(new FileInputStream(file));
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.audio.sp.AudioInputStreamPlayer#play(javax.sound.sampled.AudioInputStream)
*/
public void play(InputStream stream) {
Player player=new Player(javaSoundAudioPlayer,stream);
player.start();
}
private static class Player implements Runnable{
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
private InputStream inputStream;
private JavaSoundAudioPlayer player;
public Player(JavaSoundAudioPlayer player,InputStream inputStream){
this.inputStream=inputStream;
this.player=player;
}
/**
*
*/
public void start() {
Thread thread=new Thread(this);
thread.start();
}
public void run() {
player.play(inputStream);
}
}
}
|