-
Notifications
You must be signed in to change notification settings - Fork 247
rawAudioData
wshichang edited this page Feb 17, 2017
·
1 revision
对于某些需要获得音频原始数据的用户我们提供了OnAudioPCMListener
接口,通过此接口上层用户可以获得PCM音频数据进行使用
public interface OnAudioPCMListener {
/**
* @param buffer audio data
* @param timestamp time stamp
* @param channels the number of channels
* @param samplerate the number of samples in a single channel
* @param fmt the sample format
format:
0, ///< unsigned 8 bits
1, ///< signed 16 bits
2, ///< signed 32 bits
3, ///< float
4, ///< double
5, ///< unsigned 8 bits, planar
6, ///< signed 16 bits, planar
7, ///< signed 32 bits, planar
8, ///< float, planar
9, ///< double, planar
**/
void onAudioPCMAvailable(IMediaPlayer mp, ByteBuffer buffer, long timestamp, int channels, int samplerate, int fmt);
}
必须在调用 prepareAsync 之前设置,开发者无需申请缓存,只需要注册相应的回调接口提供给播放器即可
//[important]make sure it is called before "prepareAsync"
KSYMediaPlayer.OnAudioPCMListener AudioListener = new KSYMediaPlayer.OnAudioPCMListener() {
@Override
public void onAudioPCMAvailable(IMediaPlayer mp, ByteBuffer buffer, long timestamp, int channels, int samplerate, int fmt){
Log.e(TAG, "onAudioPCMAvailable timestamp "+ timestamp: + " channels: "+ channels+ " samplerate: "+ samplerate + " fmt: "+ fmt);
//user porcess
//........
}
};
ksyMediaPlayer.setOnAudioPCMAvailableListener(AudioListener);