如何在 ionic 7 上播放手机存储中的声音/音频?
我尝试使用 cordova-plugin-nativeaudio 如下所示
const url = await Filesystem.getUri({
directory: Directory.Documents,
path: 'test.ogg',
})
window.plugins.NativeAudio.preloadSimple('test', url.uri, function (msg) {
}, function (msg) {
console.log('error: ' + msg);
});
window.plugins.NativeAudio.play('test');
它的回报:
Msg: error: java.io.FileNotFoundException: file:///storage/emulated/0/Documents/test.ogg
如果路径来自我的应用程序公共路径,它就可以工作。但如果它来自手机存储,它就不起作用。
文档上说:
assetPath - 相对路径或绝对 URL(包括 http://) 音频资产。
但是为什么我尝试了手机存储的绝对URL仍然失败?我已经为我的应用授予了存储权限。