80,471
社区成员




m_out_buf_size1 = android.media.AudioTrack.getMinBufferSize(16000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
m_out_trk1 = new AudioTrack(AudioManager.STREAM_MUSIC, 16000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
Math.max(m_out_buf_size1*3, 10240),
AudioTrack.MODE_STREAM);
byte[] bData = ...; // 这里获取需要播放的数据
int offset = 0;
int markerInFrames = bData.length / m_out_buf_size1;
m_out_trk1.setPositionNotificationPeriod(1);
m_out_trk1.setNotificationMarkerPosition(Math.max(markerInFrames-1, 0));
m_out_trk1.setPlaybackPositionUpdateListener(this);
// 调用 m_out_trk1.write/.play/.stop
...
// 然后,实现如下代码,却发现声音正常输出了,却没有输出 onMarkerReached 字符串,问题在哪里?
@Override
public void onMarkerReached(AudioTrack track) {
// TODO Auto-generated method stub
Log.d(TAG, "onMarkerReached");
}
@Override
public void onPeriodicNotification(AudioTrack track) {
// TODO Auto-generated method stub
Log.d(TAG, "onPeriodicNotification");
}