AudioTrack: releaseBuffer() track 0xe5c6bc00 disabled due to previous underrun, restarting

Android上播放网络传过来的PCM流,启动播放十几秒后,出现声音断断续续、或无声音的状况,然后日志出现

AudioTrack: releaseBuffer() track 0xe5c6bc00 disabled due to previous underrun, restarting

网上有很多种说法,但都无法解决,后来发现通过Buffer设置可以解决。初始化的代码如下:

//每秒8K个点,双声道,一个采样点16比特-2个字节
        int minBufSize = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
        audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000,
                AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufSize, AudioTrack.MODE_STREAM);

然后修改minBufSize的大小即可,如下所示:

你可能感兴趣的:(Android,AduioTrack)