2011-08-18 69 views
3

你好,我編寫了一個程序(在Android NDK上),它通過Java中的JNI提供音頻緩衝區。不穩定的問題。有時AudioTrack完美地再現了緩衝,有時也有這些郵件:AudioTrack的問題

08-18 15:13:00.745: INFO/AudioTrack(12457): AudioTrack::set streamType[3] channels[12] format[1] sampleRate[44100] 08-18 15:13:00.749: INFO/AudioPolicyManager(2381): setOutputDevice() output 1 device 2 delayMs 0 force:0 08-18 15:13:04.183: INFO/AudioHardwareALSA(2381): Output standby called!!. Turn off PCM device.

代碼在Java中是這樣的:

final int bufSize = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT); 
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_CONFIGURATION_STEREO,AudioFormat.ENCODING_PCM_16BIT, bufSize, AudioTrack.MODE_STREAM); 
track.play(); 
int byt = track.write(buf, 0, length); 

在什麼可能是這個錯誤的問題嗎?

回答

3

您必須致電track.write並在調用track.play之前先填充最小bufSize。