【问题标题】:react-native-sound audio file not playing in iOS 13react-native-sound 音频文件未在 iOS 13 中播放
【发布时间】:2020-08-26 05:01:42
【问题描述】:
我正在使用 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()
})
【问题讨论】:
标签:
react-native
audio
ios13
playback
react-native-sound
【解决方案1】:
如果您使用 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()
})
【解决方案2】:
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(() => {});
安卓
notificationSound.play();