Running my Expo app in Chrome on Mac, the code below fails on the playAsync
call with "TypeError: sound.playAsync is not a function".
await Audio.setAudioModeAsync({
playsInSilentModeIOS: true,
staysActiveInBackground: true,
interruptionModeAndroid: InterruptionModeAndroid.DuckOthers,
shouldDuckAndroid: false,
playThroughEarpieceAndroid: false,
});
await Audio.requestPermissionsAsync();
const { sound, status } = await Audio.Sound.createAsync({ uri: audioFullUrl });
this.sound = sound;
this.sound.setOnPlaybackStatusUpdate((status: AVPlaybackStatus) => {
if (status.didJustFinish) {
console.log('Sound finished playing');
this.sound?.unloadAsync();
}
});
await sound.playAsync();
The debugger reveals that the SoundObject
sound
object has the function names, but they're all set to undefined
. What could be the cause of this?
Additional info: I don't think the requestPermissionsAsync
nor setAudioModeAsync
are necessary, but I added them while trying to diagnose this just to test. The library code in createAsync
creates the object with a simple new Sound()
, and the functions are defined with Object.assign(Sound.prototype, PlaybackMixin);
. There aren't any conditions around the loading or permissions.
Since the mixin is not being applied correctly, a workaround is to call the mixin function directly:
await PlaybackMixin.playAsync.call(sound);