To receive an AudioTrack callback, you can set a marker callback or use a periodic callback. I saw reports of marker issues, so you can try both.
To call the marker back, first call setNotificationMarkerPosition with any frame number you want to call.
For a periodic callback, instead of calling setPositionNotificationPeriod and it will call every x frames.
In any case, you need to call setPlaybackPositionUpdateListener to register the callback. This will call two methods: onMarkerReached if it reaches the token, or onPeriodicNotification for each set number of frames. You can use one or the other or both. Both callbacks refer to the AudioTrack instance that you used to install it.
By default, it will call back to the same stream, creating an instance of AudioTrack . In addition, you can pass a handler when registering callbacks to send it to another thread.
source share