0

我正在使用react-native-sound并在 iOS 12 设备上播放声音,但是当我签入 iOS 13 设备时没有播放。

这是我的代码

this.soundPlayer = new Sound(require('../assets/fly.mp3'), '', (error) => {
      console.log(error)
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
      this.soundPlayer.play()
    })
4

2 回答 2

0
const notificationSound = new Sound('ring_tone.wav', Sound.MAIN_BUNDLE, (error) => {
    if (error) {
        console.log('failed to load the sound', error);
        return;
    }
});
enter code here

请在 ios notificationSound.play(() => {});中使用以下方式

Android notificationSound.play();

于 2021-09-20T13:22:04.880 回答
0

如果您使用require然后使用加载声音

this.soundPlayer = new Sound(require('../assets/fly.mp3'), (error) => {
      console.log(error)
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
      this.soundPlayer.play()
    })

当您在网络中加载声音时,请使用

this.soundPlayer = new Sound(require('../assets/fly.mp3'), '', (error) => {
      console.log(error)
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
      this.soundPlayer.play()
    })
于 2020-08-26T10:27:26.830 回答