我有文件选择器从本地存储中选择音频文件,文件选择器的结果如下
size: 1057931
name: "AUD-20190314-WA0019.m4a"
type: "audio/mpeg"
uri: "content://com.android.externalstorage.documents/document/primary%3AWhatsApp%2FMedia%2FWhatsApp%20Audio%2FAUD-20190314-WA0019.m4a"
我目前正在使用 react-native-sound 从选择器中播放选定的音频文件
var whoosh = new Sound(audio, Sound.MAIN_BUNDLE, error => {
if (error) {
console.log('failed to load the sound', error);
return;
}
// loaded successfully
console.log(
'duration in seconds: ' +
whoosh.getDuration() +
'number of channels: ' +
whoosh.getNumberOfChannels(),
);
// Play the sound with an onEnd callback
whoosh.play(success => {
if (success) {
console.log('successfully finished playing');
} else {
console.log('playback failed due to audio decoding errors');
}
});
}
(音频变量是文件选择器中恢复的 uri)
但是这种方法不播放音频文件而不是播放,它给我留下了错误
无法加载声音{消息:“找不到资源”,代码:-1}
我做错了什么,我怎样才能播放从文件选择器中选择的音频文件?