1、OH\_AVPlayer\_SetURLSource支持网络和静态路径,比如:const char *path = "/vendor/test/123.mp3"; int32_t ret1 = OH_AVPlayer_SetURLSource(audio_player_, path);2、rawfile、沙箱下的用OH\_AVPlayer\_SetFDSource接口实现,比如:async a(){ // 把音频文件写到沙箱路径中 const resourceManager = getContext(this).resourceManager const imageArray = await resourceManager.getMediaContent($r('app.media.123')); let path: string = getContext().filesDir + "/123.mp3"; console.log("yuv_path is:" + path); let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); fs.write(file.fd, imageArray.buffer).then((writeLen) => { console.info("write data to file succeed and size is:" + writeLen); fs.closeSync(file); }).catch((err: BusinessError) => { console.info("write data to file failed with error message: " + err.message + ", error code: " + err.code); }); let fd = file.fd; let off = fs.lseek(file.fd, 5, fs.WhenceType.SEEK_SET) testNapi.init(fd, off); } int32_t ret1 = OH_AVPlayer_SetFDSource(player, fd, off, -1); //注:-1代表长度
1、OH\_AVPlayer\_SetURLSource支持网络和静态路径,比如:
2、rawfile、沙箱下的用OH\_AVPlayer\_SetFDSource接口实现,比如: