mport java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Control; import javax.sound.sampled.DataLine; import javax.sound.sampled.FloatControl; import javax.sound.sampled.Line; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.Mixer; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.UnsupportedAudioFileException; import javazoom.spi.PropertiesContainer; import org.tritonus.share.sampled.TAudioFormat; import org.tritonus.share.sampled.file.TAudioFileFormat; import static com.hadeslee.yoyoplayer.player.BasicPlayerEvent.*; /** * BasicPlayer is a threaded simple player class based on JavaSound API. * It has been successfully tested under J2SE 1.3.x, 1.4.x and 1.5.x. */ @SuppressWarnings("unchecked") public class BasicPlayer implements BasicController, Runnable { public static int EXTERNAL_BUFFER_SIZE = 4000 * 4; public static int SKIP_INACCURACY_SIZE = 512; protected Thread m_thread = null; protected Object m_dataSource; protected AudioInputStream m_encodedaudioInputStream; protected int encodedLength = -1; protected AudioInputStream m_audioInputStream; protected AudioFileFormat m_audioFileFormat; protected SourceDataLine m_line; protected FloatControl m_gainControl; protected FloatControl m_panControl; protected String m_mixerName = null; private int m_lineCurrentBufferSize = -1; private int lineBufferSize = -1; private long threadSleep = -1; private static Logger log = Logger.getLogger(BasicPlayer.class.getName()); /** * These variables are used to distinguish stopped, paused, playing states. * We need them to control Thread. */ // public static final int UNKNOWN = -1; // public static final int PLAYING = 0; // public static final int PAUSED = 1; // public static final int STOPPED = 2; // public static final int OPENED = 3; // public static final int SEEKING = 4; private int m_status = UNKNOWN; private Map empty_map = new HashMap(); private BasicPlayerEventLauncher laucher;//浜嬩欢鍒嗘淳鍣? /** * Constructs a Basic Player. */ public BasicPlayer() { m_dataSource = null; laucher = new BasicPlayerEventLauncher(); laucher.start(); reset(); } protected void reset() { m_status = UNKNOWN; if (m_audioInputStream != null) { synchronized (m_audioInputStream) { closeStream(); } } m_audioInputStream = null; m_audioFileFormat = null; m_encodedaudioInputStream = null; encodedLength = -1; if (m_line != null) { m_line.stop(); m_line.close(); m_line = null; } m_gainControl = null; m_panControl = null; } /** * Add listener to be notified. * @param bpl */ public void addBasicPlayerListener(BasicPlayerListener bpl) { laucher.addBasicPlayerListener(bpl); } /** * Return registered listeners. * @return */ public Collection getListeners() { return laucher.getBasicPlayerListeners(); } /** * Remove registered listener. * @param bpl */ public void removeBasicPlayerListener(BasicPlayerListener bpl) { laucher.removeBasicPlayerListener(bpl); } /** * Set SourceDataLine buffer size. It affects audio latency. * (the delay between line.write(data) and real sound). * Minimum value should be over 10000 bytes. * @param size -1 means maximum buffer size available. */ public void setLineBufferSize(int size) { lineBufferSize = size; } /** * Return SourceDataLine buffer size. * @return -1 maximum buffer size. */ public int getLineBufferSize() { return lineBufferSize; } /** * Return SourceDataLine current buffer size. * @return */ public int getLineCurrentBufferSize() { return m_lineCurrentBufferSize; } /** * Set thread sleep time. * Default is -1 (no sleep time). * @param time in milliseconds. */ public void setSleepTime(long time) { threadSleep = time; } /** * Return thread sleep time in milliseconds. * @return -1 means no sleep time. */ public long getSleepTime() { return threadSleep; } /** * Returns BasicPlayer status. * @return status */ public int getStatus() { return m_status; } /** * Open file to play. */ public void open(File file) throws BasicPlayerException { log.info("open(" + file + ")"); if (file != null) { m_dataSource = file; initAudioInputStream(); } } /** * Open URL to play. */ public void open(URL url) throws BasicPlayerException { log.info("open(" + url + ")"); if (url != null) { m_dataSource = url; initAudioInputStream(); } } /** * Open inputstream to play. */ public void open(InputStream inputStream) throws BasicPlayerException { log.info("open(" + inputStream + ")"); if (inputStream != null) { m_dataSource = inputStream; initAudioInputStream(); } }
- 1
- 2
- 3
- 4
- 5
- 6
- 粉丝: 0
- 资源: 10
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 焊接件旋转弯曲疲劳极限性能研究.pdf
- 焊接接头残余应力数值模拟.pdf
- 焊接接头的抗动载断裂特性 - .pdf
- 焊接接头强度匹配和焊缝韧性指标综述.pdf
- 焊接接头疲劳行为研究.pdf
- 焊接接头设计(1999第三版).pdf
- 焊接接头型式和焊缝符号.pdf
- 机械设计吹气式桌面双工位螺丝机sw18可编辑全套设计资料100%好用.zip
- 焊接接头中的裂纹对风险检验结果的影响.pdf
- 焊接结构 田锡唐.pdf
- 焊接结构焊缝中缺陷参数不确定性处理方法.PDF
- 焊接结构耐候钢新旧标准牌号对照表.pdf
- 焊接结构件焊接变形的控制.pdf
- 焊接结构强度和断裂.pdf
- 焊接结构设计手册.pdf
- 焊接结构纵梁检测校正装置开发.pdf