expo app playing sounds on return from multitasking
See original GitHub issueFor some reason when I return from multitasking to the app , the click sound that I have programmed in, plays. It doesn’t play the sound if the function was never called while the user was using the app. So for example if the user used the app without ever triggering the sound it won’t play when returning from the multitasking screen. However , if the user has triggered the sound once or more than once the sound will play that many times on return. This behavior can also be noticed when pulling down the notification bar or when a pop up notification appears for low battery.
Code:
class Home extends Component {
Play() {
this.clickSound();
}
async clickSound() {
const soundObject = new Expo.Audio.Sound();
try {
await soundObject.loadAsync(loadedClickSound);
await soundObject.playAsync(loadedClickSound);
} catch (error) {
}
}
render() {
return (
<Button title="PLAY" large onPress={() => this.Play()} />
);
}
}
Things I have tried :
-
Adding soundObject.unloadAsync() in componentWillUnmount
-
The same thing but right after the sound plays. Although this just causes the sound not to play at all.
Note: I only have an IOS device not sure if the issue can be recreated on android
Second Note: This isn’t the same as #1329, cause in that case, the un-played sounds played afterwards
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Thank you for the reports. This appears to be an bug with Expo iOS and is a known issue. We don’t have a fix slated for SDK 26 but please see my post above for a conceptual workaround. There is a small example here: https://github.com/ide/love-languages/blob/6fd73d3c85a13db60fbc0c22b26d88b3feeb3cbe/app/assets/Sounds.js#L39-L43
This issue has been fixed in https://github.com/expo/expo/commit/3835682976a0ec1c0604654546f5e6f5c77c8de5, which will ship in SDK 26. 😃