文件名称:
ym_java-YOYOPlayer-src
开发工具:
文件大小: 2mb
下载次数: 0
上传时间: 2011-03-24
详细说明: 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(); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.