Sounds stop working if you spam click faces and/or the doorbell button
There is a problem with expo-av where spamming ring buttons prevents ring sounds to working until app restart. It might be related to how many sounds can be played at the same time. There should be a way to limit that.
Here's the current code for playing the ring sound:
async function playDoorbellSound() {
const sound = new Audio.Sound()
try {
await sound.loadAsync(require('./assets/sounds/doorbell.mp3'))
await sound.playAsync()
}
catch (error) {
console.error(error)
}
}
It's possible to limit the number of playing sounds e.g. by adding a counter using global variables:
const PLAYING_SOUNDS_LIMIT = 8
let playingSoundsCounter = 0
Now we could maybe fix the problem like this (not tested!):
async function playDoorbellSound() {
if(playingSoundsCounter > PLAYING_SOUNDS_LIMIT) return
const sound = new Audio.Sound()
try {
playingSoundsCounter++
await sound.loadAsync(require('./assets/sounds/doorbell.mp3'))
await sound.playAsync()
playingSoundsCounter--
}
catch (error) {
// Maybe we should send error messages to backend which would send them to some proprietary Slack channel
console.error(error)
}
}
Just an idea, there might be some settings in expo-av that would prevent this error with too many simultaneous sounds / spamming sounds.
Edited by Petteri Saurus