Problem Description: I recently upgraded my Expo project from SDK 49 to SDK 51, and I’m facing an issue with the onPlaybackStatusUpdate
callback in the expo-av library. Prior to the upgrade, everything was working fine on both iOS and Android. However, after upgrading, the onPlaybackStatusUpdate callback only fires when I start or stop playback on Android, but it works correctly on iOS.
Steps to Reproduce:
- Create a new Expo project using SDK 51.
- Add audio files to your project (e.g., MP3 files).
- Implement audio playback using expo-av.
- Set up the onPlaybackStatusUpdate callback to monitor playback
status changes. - Run the app on both Android and iOS devices
- Observe that the callback fires as expected on iOS but not
consistently on Android. Expected Behavior: The
onPlaybackStatusUpdate callback should fire consistently on both
Android and iOS, providing updates on playback status (e.g.,
position, duration, buffering, etc.) every 100ms.
Actual Behavior: On Android, the onPlaybackStatusUpdate
callback only fires when playback starts or stops, but not at regular intervals as expected.
Additional Information:
-
I’ve checked my code thoroughly and ensured that there are no
logical errors related to the callback registration. -
I’ve tested this behavior on multiple Android devices with
the same result. -
The issue seems specific to Android after upgrading to SDK 51.
Environment:
- Expo SDK: 51
- Platform: Android (iOS works as expected)
3, Device: Android devices
Code Snippet:
import { Audio } from 'expo-av';
// ... Other setup code ...
const loadAudio = async () => {
const soundObject = new Audio.Sound();
try {
await soundObject.loadAsync(require('./path/to/audio.mp3'));
soundObject.setOnPlaybackStatusUpdate((status) => {
console.log('Playback status:', status);
// Handle playback status updates here
});
} catch (error) {
console.error('Error loading audio:', error);
}
};
// Call loadAudio() somewhere in your app
I appreciate any insights or solutions to resolve this issue. Thank
you in advance!
2
Answers
I faced the same issue. In a meantime, I added a fix that does that ‘playback update’ logic on Android.
Here is a code sample:
I believe expo-av has undergone some internal changes. While answering this question I do recall encountering audio examples that no longer worked. Also in that answer I created a hook that allows you to fine tune the number of intervals between updates (and other things) Demo: