With react-native-sound and react-native-background-timer, I want to play a sound after 10 seconds delay.
Here is my very simple code :
import BackgroundTimer from 'react-native-background-timer'
import Sound from 'react-native-sound'
Sound.setCategory('Playback')
const soundEnd = new Sound('end.mp3', Sound.MAIN_BUNDLE)
const Timer = () => {
useEffect(
() => {
const timeoutId = BackgroundTimer.setTimeout(() => {
console.log('END setTimeout')
soundEnd.play(() => {})
}, 10000)
return () => {
BackgroundTimer.clearTimeout(timeoutId)
}
},
[]
)
}
console.log('END setTimeout')
is displayedconsole.log('END setTimeout')
is displayed well)Can you help me ? According to react-native-background-timer, the sounds are supposed to play in the background
on ios, you need to first enable UIBackgroundModes from Xcode and then add this in Info.plist.
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>