【发布时间】:2019-11-20 09:02:24
【问题描述】:
在我的应用中,我有一个功能可以在收到消息时播放声音,它会通过播放声音文件来通知用户,该应用在 Android 中使用 react-native-sound 可以正常工作,但是在 iOS 中,我不断收到此错误:
我用于初始化声音的代码:
import Sound from "react-native-sound"
// Load the sound file 'whoosh.mp3' from the app bundle
// See notes below about preloading sounds within initialization code below.
var message_received = new Sound(require("../../res/audio/Page_Turn.mp3"), Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
// loaded successfully
console.log('duration in seconds: ' + message_received.getDuration() + 'number of channels: ' + message_received.getNumberOfChannels());
});
初始化声音文件后调用的方法:
message_received.play()
有人知道怎么解决吗?
【问题讨论】:
-
来自 react-native-sound 文档:iOS:打开 Xcode 并将您的声音文件添加到项目中(右键单击项目并选择将文件添加到 [PROJECTNAME])。然后你可以像 new Sound('Page_Turn.mp3',
-
我这样做了,但仍然遇到同样的错误。
-
执行 .play() 或初始化声音时出现错误?
-
@llario 您的解决方案有效,谢谢!
-
太棒了!请问你能接受我的回答吗? :)
标签: javascript ios react-native react-native-sound