【问题标题】:react-native-sound does not work on ios emulatorreact-native-sound 在 ios 模拟器上不起作用
【发布时间】:2020-09-13 22:46:32
【问题描述】:

以下代码在 android 上运行良好,并且可以播放声音....但是在 ios 模拟器上却不行。 我已经将我的声音文件添加到 Xcode 项目中,并且没有发现任何错误......当我单步执行代码时,它成功运行 this.sound.play() 并调用了回调函数......但是你没有听到任何声音。

import Sound from 'react-native-sound';

sound = new Sound('sound.mp3');
try {
    this.sound.setCategory('Playback');
    this.sound.play(() => {
       this.sound.stop();
       this.sound.release();
    });
    } catch (e) {
       console.log('cannot play the sound file', e);
    }

【问题讨论】:

    标签: react-native react-native-ios react-native-sound


    【解决方案1】:

    如果您有最新的 Xcode 11.6,您是否尝试过修改中的设置

    Simulator > I/O > Audio Output

    (如果是较旧的 xcode,可能是 Simulator > Hardware > Audio Output)?

    【讨论】:

    • 在音频输出中显示了 2 个选项,但都不起作用
    【解决方案2】:

    你放了声音文件的地方,请注意声音剪辑文件应该放在目录 android/app/src/main/res/raw 对于 android 和对于 iOS,将你的声音添加到 Xcode 项目中的资源

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-15
      • 2017-05-14
      • 2018-05-05
      • 2019-08-07
      • 2018-03-18
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多