HarmonyOS 鸿蒙Next如何播放本地mp3文件

HarmonyOS 鸿蒙Next如何播放本地mp3文件

HarmonyOS 鸿蒙Next如何播放本地mp3文件

playSound() { //创建soundPool实例 let soundPool: media.SoundPool; let audioRendererInfo: audio.AudioRendererInfo = { usage: audio.StreamUsage.STREAM_USAGE_MUSIC, rendererFlags: 1 } media.createSoundPool(5, audioRendererInfo, (error: BusinessError, soundPool_: media.SoundPool) => { if (error) { console.log(‘zd----’, Failed to createSoundPool) return; } else { soundPool = soundPool_; console.log(‘zd----’, Succeeded in createSoundPool) let file: fileIo.File; let soundID: number = 0; let fileSize: number = 1; //通过fileIo.stat()获取size值 let uri: string = “”; //获取fd的描述信息 fileIo.open(’…/…/resources/rawfile/kazicui.mp3’, fileIo.OpenMode.READ_ONLY).then((file_: fileIo.File) => { file = file_; console.log(‘zd----’, "file fd: " + file.fd); uri = ‘fd://’ + (file.fd).toString() soundPool.load(file.fd, 0, fileSize).then((soundId: number) => { console.log(‘zd----’, ‘Succeeded in loading soundpool’); soundID = soundId; }, (err: BusinessError) => { console.log(‘zd----’, 'Failed to load soundpool and catch error is ’ + err.message); }); }).catch((e: BusinessError) => { console.log(‘zd----’, ‘Failed to load soundpool and catch error is ’ + e.message + ’ code:’ + e.code); }); } }); } 提示Failed to load soundpool and catch error is No such file or directory code:13900002 音频文件要放在哪里

相关推荐

资格考试软件哪个最好用 最新资格考试软件排行
解决TIM聊天记录迁移问题:自定义路径及配置教程
穿越火线下载包在哪个文件夹 穿越火线下载的文件可以删除吗
网卡:物理链路层的关键组件与分类

本文标签