Here is what I learned.
For me, frames are samples. This is the duration of sound multiplied by the sampling rate.
To use AudioTrack setPositionNotificationPeriod, you pass the number of samples. If you pass 200 samples, a callback will be called every 200 samples that are repeated.
tmpAudioTrack.setPositionNotificationPeriod(duration * sampleRate);
To use setNotificationMarkerPosition, you also pass the number of samples. However, this is absolute and not relative, as for the period API. Therefore, if you want to determine when the sound ends, you transmit the number of samples (total duration of the audio track * sampleRate).
tmpAudioTrack.setNotificationMarkerPosition(duration * sampleRate);
But if you are already playing in the middle of your audio track and want to add a marker so that you get a callback, say after 3 seconds, then you will need to add the current point of sound playback to the track, for example: (where your duration is 3 seconds)
tmpAudioTrack.setNotificationMarkerPosition(tmpAudioTrack.getPlaybackHeadPosition() + (duration * sampleRate));
And so you register for period and brand notifications.
tmpAudioTrack.setPlaybackPositionUpdateListener(new OnPlaybackPositionUpdateListener(){ @Override public void onMarkerReached(AudioTrack arg0) { } @Override public void onPeriodicNotification(AudioTrack arg0) { }
});
mikemeli
source share