Minim.java 文件源码

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

项目:romanov 作者:
/**
 * Loads the requested file into an {@link AudioPlayer} with the request
 * buffer size.
 * 
 * @param filename
 *            the file or URL you want to load
 * @param bufferSize
 *            int: the sample buffer size you want, which determines the 
 *            size of the left, right, and mix AudioBuffer fields of the 
 *            returned AudioPlayer.
 * 
 * @return an <code>AudioPlayer</code> with a sample buffer of the requested
 *         size, or null if we were unable to load the file
 */
public AudioPlayer loadFile(String filename, int bufferSize)
{
    AudioPlayer player          = null;
    AudioRecordingStream rec    = mimp.getAudioRecordingStream( filename, bufferSize, false );
    if ( rec != null )
    {
        AudioFormat format  = rec.getFormat();
        AudioOut out        = mimp.getAudioOutput( format.getChannels(),
                                                   bufferSize, 
                                                   format.getSampleRate(),
                                                   format.getSampleSizeInBits() );

        if ( out != null )
        {
            player = new AudioPlayer( rec, out );
        }
        else
        {
            rec.close();
        }
    }

    if ( player != null )
    {
        addSource( player );
    }
    else
    {
        error( "Couldn't load the file " + filename );
    }

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


问题


面经


文章

微信
公众号

扫码关注公众号