AudioPlayer.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:pumpernickel 作者:
/** Plays audio from the given audio input stream.
 * 
 * @param stream the AudioInputStream to play.
 * @param startTime the time to skip to when playing starts.
 * A value of zero means this plays from the beginning, 1 means it skips one second, etc.
 * @param listener an optional Listener to update.
 * @param cancellable an optional Cancellable to consult.
 * @param blocking whether this call is blocking or not.
 * @throws LineUnavailableException if a line is unavailable.
 * @throws UnsupportedOperationException if this static method doesn't support playing the stream argument
 **/
public static SourceDataLine playAudioStream(AudioInputStream stream,StartTime startTime,Listener listener,Cancellable cancellable,boolean blocking) throws UnsupportedOperationException, LineUnavailableException {
    AudioFormat audioFormat = stream.getFormat();
    DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
    if ( !AudioSystem.isLineSupported( info ) ) {
        throw new UnsupportedOperationException("AudioPlayback.playAudioStream: info="+info );
    }

    final SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
    dataLine.open( audioFormat );
    dataLine.start();

    PlayAudioThread thread = new PlayAudioThread(stream, startTime, dataLine, listener, cancellable);
    if(blocking) {
        thread.run();
    } else {
        thread.start();
    }

    return dataLine;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号