簡體   English   中英

我怎樣才能停止 Expo-AV REACT NATIVE 的聲音

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

我正在使用這個 function 來播放聲音文件。 我希望單擊按鈕時聲音停止

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)=>{});
  }

創建聲音時,您只需將其分配給一個值

const { sound } = await Audio.Sound.createAsync(asset);

然后你可以使用其他方法的聲音 object

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

ETC

希望能幫助到你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM