Please provide the following:
- SDK Version: 44
- Platforms(Android/iOS/web/all): iOS
- Add the appropriate “Tag” based on what Expo library you have a question on.
I’m trying to use the Expo-AV module to play short audio clips and I’m not sure of the best way to load, unload and play them.
The app is a timer app that will play different sounds based on what time it is. For example, every 15 seconds, play “gong”, every minute, play “chime”, last 5 seconds, each second play “ding”.
Currently, I’m using a function like this, which is storing the “soundToPlay” in a global variable so that I can unload it. Not sure if that would be a memory leak if I didn’t.
I’m not sure if this is even close to the way you might approach this.
async function playSound(whichSoundtoPlay: AssetNames) {
if (soundToPlay) {
soundToPlay.unloadAsync();
}
const { sound } = await Audio.Sound.createAsync(alertSounds[whichSoundtoPlay]);
// await sound.unloadAsync();
soundToPlay = sound;
await soundToPlay.playAsync();
}
I’m open to any ideas!
Thanks!