I have this function in react native
with expo-av
const PLAY = async(uri: string, index: number) =>
{
if(currentSound)
{
await currentSound.stopAsync()
await currentSound.unloadAsync()
}
if(uri)
{
await Audio.setAudioModeAsync({ playsInSilentModeIOS: true })
const { sound } = await Audio.Sound.createAsync({ uri }, { shouldPlay: true }, FINISH_AUDIO)
setCurrentSound(sound)
await sound.playAsync()
setPlayingIndex(index)
setIsPlaying(true)
}
else
{
console.error('No sound URI found in AsyncStorage');
}
}
This works well for me to play audios that I record and store in my AsyncStorage
, the problem is that I cannot detect when the audio ended, according to the documentation it should be able to be achieved with the FINISH_AUDIO
function that has this
const FINISH_AUDIO = async(status: AVPlaybackStatus) =>
{
console.log(status)
if(status.isLoaded)
{
if(status.didJustFinish)
{
setIsPlaying(false)
setPlayingIndex(null)
setCurrentSound(null)
}
}
}
This function runs fine when the audio starts playing, but it doesn’t go back in there when the audio has finished. Am I doing something wrong or am I missing some extra step?