zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 748 forks source link

Get a callback when playback has reached the end #719

Closed kg-currenxie closed 3 years ago

kg-currenxie commented 3 years ago

:clipboard: Description

Get a callback when playback has reached the end.

:microphone: Motivation

I have several clips that I would like to play in a sequence. I have to know when a sound has finished playing so I can start the next one.

:bulb: Alternatives

SetInterval and checking currentTime, comparing to the total length 🤦 Not good.

akk7300 commented 3 years ago

// Play the sound with an onEnd callback whoosh.play((success) => { if (success) { console.log('successfully finished playing'); this.nextSong(); } else { console.log('playback failed due to audio decoding errors'); } }); });

kg-currenxie commented 3 years ago

I misread the docs :) Thanks