更新记录
1.1(2023-08-21)
修复已知问题,优化体验;
1.0(2023-08-14)
音频录制支持实时帧回调,支持Mp3录制和实时回调,支持获取录音文件路径,支持文件转实时帧回调,支持pcm转wav,支持pcm播放,支持采样率,声道,位深等参数设置
平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:4.4 - 12.0 | armeabi-v7a:支持,arm64-v8a:支持,x86:未测试 | × |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
插件说明:YL-AudioRecorder升级版,支持Mp3录制
由于uni提供的录音管理器uni.getRecorderManager(),不支持APP上的实时回调,由此便诞生了该原生录音插件。
该录音插件支持PCM录音实时帧回调,支持获取录音文件路径,支持pcm转wav,支持pcm播放,
支持设置录音参数如采样率,声道,位深等;
需要注意的是,目前该插件仅支持安卓端,不支持IOS!
YL-AudioRecorderPlus是对YL-AudioRecoder的升级版,在YL-AudioRecoder的基础上,增加了对mp3音频格式录制的支持并支持实时回调。
当你有这样的需求:你需要实时上传录音数据,但你现在只有一个录制好的音频文件,怎么办? 此时,你就可以调用plus版本插件中的getAudioFrame方法,将音频文件转化为字节流,模拟实时帧回调。
1.使用方法:
- 1.普通录制参考YL-AudioRecoder
注意插件id需修改为:YL-AudioRecorderPlus
引入方式:const ar = uni.requireNativePlugin("YL-AudioRecorderPlus");
- 2.Mp3录制:
ar.startMp3Record(res => {
//res:{"buffer":[],"isLast":false}
});
- 3.停止录制:
ar.stopMp3Record(res => {
});
- 4.获取音频文件实时帧回调:
ar.getAudioFrame(this.path, res => {
//res:{"buffer":[],"isLast":false}
});
- 5.销毁:
ar.release();
代码示例:
<template>
<div style="padding: 20rpx;">
<button type="primary" @click="start" style="margin-top: 20rpx;">开始录制Mp3</button>
<button type="primary" @click="stop" style="margin-top: 20rpx;">停止录音</button>
<button type="primary" @click="play" style="margin-top: 20rpx;">播放Mp3</button>
<button type="primary" @click="getAudioFrame" style="margin-top: 20rpx;">文件转实时帧</button>
<div style="margin-top: 20rpx;">
<text class="text">实时回调:{{data}}</text>
</div>
<div style="margin-top: 20rpx;">
<text class="text">录音文件路径:{{path}}</text>
</div>
</div>
</template>
<script>
const ar = uni.requireNativePlugin("YL-AudioRecorderPlus");
export default {
data() {
return {
data: "",
path: ""
}
},
mounted() {
},
beforeDestroy() {
ar.release();
},
methods: {
start() {
ar.startMp3Record(res => {
this.data = "" + res.buffer + "," + res.isLast;
});
},
stop() {
ar.stopMp3Record(path => {
this.path = path;
});
},
play() {
if (this.path) {
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.src = this.path;
innerAudioContext.play();
}
},
getAudioFrame() {
if (this.path) {
ar.getAudioFrame(this.path, res => {
this.data = JSON.stringify(res);
});
}
}
}
}
</script>
<style>
.text {
line-height: 1.5;
text-align: justify;
word-wrap: break-word;
}
</style>
联系方式QQ:453503875,微信:bylss311