AudioTrack notification message

I implemented a PCM decoder that records an AudioTrack object.

Everything seems great, but I need to get some kind of notification from the AudioTrack when the last recorded fragment stops playing.

I noticed that there are callback methods like setNotificationMarkerPosition, , however I could not find extensive documentation on how to use them.

Thanks in advance!

+4
source share
1 answer

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.

+2
source

Source: https://habr.com/ru/post/1334855/


All Articles