HarmonyOS鸿蒙Next中使用soundPool播放本地文件报错 13900002
HarmonyOS鸿蒙Next中使用soundPool播放本地文件报错 13900002
async load() {
try {
await fs.open('./test.mp3', fs.OpenMode.READ_ONLY).then((file: fs.File) => {
console.info("file fd: " + file.fd);
this.uri = 'fd://' + (file.fd).toString()
});
soundPool.load(this.uri).then((soundId: number) => {
console.info('soundPool load uri success');
// soundID = soundId;
}).catch((err: BusinessError) => {
console.error('soundPool load failed and catch error is ' + err.message);
})
} catch (e){
console.log("error", JSON.stringify(e))
}
}
使用官方的例子,test.mp3文件就在同级目录下(试了./test.mp3和/test.mp3)但是都遇到了一样的报错 “code”:13900002 不知道该如何解决
更多关于HarmonyOS鸿蒙Next中使用soundPool播放本地文件报错 13900002的实战教程也可以访问 https://www.itying.com/category-93-b0.html
播放文件需要先复制到应用沙箱下面,才能播放,不能通过uri直接播放。
更多关于HarmonyOS鸿蒙Next中使用soundPool播放本地文件报错 13900002的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
请问什么是应用沙箱呀,
<div>
<p>应用沙箱是一种安全措施,用于隔离应用程序或其部分组件,以防止它们相互干扰或访问敏感数据。</p>
</div>
我的代码没问题,但是我test.mp3的位置放置的不对?
确保soundPool已初始化
初始化SoundPool...
开始加载音频文件…
准备加载音频,文件路径: /data/storage/el2/base/haps/entry/resources/rawfile/test.mp3
音频加载成功,soundId: [soundId]
音频开始播放
SoundPool加载失败: {“code”:5400102,“name”:“BusinessError”}
在HarmonyOS鸿蒙Next中使用SoundPool播放本地文件时,报错13900002通常是由于文件路径或资源加载问题引起的。请检查以下几点:
-
确保文件路径正确,且文件存在于指定位置。
-
确认文件格式支持,SoundPool支持WAV、MP3等格式。
-
检查文件权限,确保应用有读取文件的权限。
-
使用
SoundPool.load()
方法加载文件时,确保返回的soundID有效。 -
如果问题依旧,尝试重新编译或清理项目缓存。