I'm using this function for the play sound files. I want the sound to stop when I click the button
function playSound(){
Audio.Sound.createAsync(
selectedAnimals.soundUrl,
{ shouldPlay: true }
).then((res)=>{
res.sound.setOnPlaybackStatusUpdate((status)=>{
if(!status.didJustFinish) return;
res.sound.unloadAsync().catch(()=>{});
});
}).catch((error)=>{});
}
when creating the sound you simply need to assign it to a value
const { sound } = await Audio.Sound.createAsync(asset);
and then you can use other methods of the sound object
await sound.sound.pauseAsync()
await sound.sound.stopAsync()
etc
hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.