简体   繁体   English

我怎样才能停止 Expo-AV REACT NATIVE 的声音

[英]How can i stop the sound on Expo-AV REACT NATIVE

I'm using this function for the play sound files.我正在使用这个 function 来播放声音文件。 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然后你可以使用其他方法的声音 object

await sound.sound.pauseAsync()
await sound.sound.stopAsync()

etc ETC

hope it helps希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM