更新记录

1.4.0(2023-07-21)

本次主要更新: 1.andorid修复实时回调 framebase64返回不正确 和 pcm文件大小为0的情况

1.3.0(2023-06-29)

本次主要更新: 1.修复andorid13 start方法配置isService为true,闪退的bug 2.ios修复 format 不生效的问题 3.ios resume方法增加 音频恢复

1.2.0(2023-06-15)

本次主要更新: 1.ios onFrameRecorded 实时帧回调 增加 decibel 分贝值返回

查看更多

平台兼容性

Android Android CPU类型 iOS
适用版本区间:4.4 - 12.0 armeabi-v7a:支持,arm64-v8a:支持,x86:支持 适用版本区间:11 - 16

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
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原生插件配置”->”云端插件“列表中删除该插件重新选择


KJ-AudioV2

录音支持实时帧pcm回调、暂停、继续、后台录音、息屏录音、长时间录音

注意

    1.andorid需要配置:manifest.json -> app-plus -> distribute -> android -> targetSdkVersion  
    targetSdkVersion 要设置 >= 23

    2.andorid 自定义通知的图标和小图标,不设置的话,默认是插件里的默认图标
    需要在 主目录->nativeplugins->KJ-AudioV2->android->res->drawable 下配置添加 kj_audio_v2_push_small.png(小图标) 和 kj_audio_v2_push.png(图标)
    详情下载参考示例项目

    小图标设计要求是特殊的, 特别需要注意以下两点:
        a.必须是透明的底;
        b.内部形状颜色为白色最佳; (是其他颜色也可以, 但好像最终也会转成,通知栏显示白色, 通知左上角图标灰色)

andorid push_small小图标注意事项:https://ask.dcloud.net.cn/article/39429

后台录音 不保证所有手机有效

    ios:
    manifest.json->App常用其它设置->后台运行能力  填入“audio” 然后运打包
    andorid:
    KJAudio.start 的isService参数设置为true

使用

<template>
    <view class="content">
        <button type="primary" @click="start">开始录音</button>
        <view class="json">{{Json}}</view>
        <button type="primary" @click="pause">暂停</button>
        <button type="primary" @click="resume">恢复</button>
        <button type="primary" @click="stop">停止</button>
        <view class="json">实时帧:{{onFrameRecordedJson}}</view>
    </view>
</template>

<script>
    var KJAudioV2 = uni.requireNativePlugin("KJ-AudioV2");
    export default {
        data() {
            return {
                Json: "",
                onFrameRecordedJson: ""
            }
        },
        onLoad() {
            var globalEvent = uni.requireNativePlugin('globalEvent');
            globalEvent.addEventListener('onFrameRecorded', (res) => {
                console.log('onFrameRecorded:');
                this.onFrameRecordedJson = JSON.stringify(res);
            });
            globalEvent.addEventListener('', (res) => {
                console.log(':' + JSON.stringify(res));
                this.Json = JSON.stringify(res);
            });
            globalEvent.addEventListener('', (res) => {
                console.log(':' + JSON.stringify(res));
                if (res.type == "systemPause") { //ios 通话的时候,系统会自动暂停,andorid,不受影响,只是不能录制,电话挂了之后,会继续录音
                    console.log("系统暂停");
                }
            });
        },
        methods: {
            start() {
                var dic = {
                    "filePath": plus.io.convertLocalFileSystemURL("_doc/KJ-AudioV2"),
                    "format": "wav", //最终音频格式,有效值 wav/pcm
                    "sampleRate": 8000, //采样率,有效值 8000/16000/44100
                    "numberOfChannels": 2, //录音通道数,有效值 1/2
                    "isService": true, //android才支持,是否开启后台服务,在后台和熄屏都可以录音
                    "notificationID": "KJ-Audio10", //android8才支持,通知ID
                    "notificationName": "主服务", //android8才支持,通知名
                    "notificationTitle": "录音服务", //android才支持,通知标题
                    "notificationText": "运行中...", //android才支持,通知内容
                    "isSetNotificationVibrate": false, //android才支持,是否设置震动,由于android机制,通知设置过了,就不能再修改,如果要修改,要先修改notificationID
                    "isRequestPermissions": true, //android才支持,是否申请RECORD_AUDIO权限
                    /**以下是指定帧参数,格式pcm**/
                    "frameFilePath": plus.io.convertLocalFileSystemURL("_doc/KJ-AudioV2-frame"), //指定帧保存pcm文件的路径
                    "isFrameBase64": true, //是否返回指定帧的base64
                    "frameSize": 10, //KB 指定帧大小,单位 KB
                };
                KJAudioV2.start(dic, (res) => {
                    console.log("start:" + JSON.stringify(res))
                })
            },
            pause() {
                KJAudioV2.pause((res) => {
                    console.log("pause:" + JSON.stringify(res))
                })
            },
            resume() {
                KJAudioV2.resume((res) => {
                    console.log("resume:" + JSON.stringify(res))
                })
            },
            stop() {
                KJAudioV2.stop((res) => {
                    console.log("stop:" + JSON.stringify(res))
                    const innerAudioContext = uni.createInnerAudioContext();
                    innerAudioContext.autoplay = true;
                    innerAudioContext.src = res.filePath;
                    innerAudioContext.onPlay(() => {
                        console.log('开始播放');
                    });
                    innerAudioContext.onError((res) => {
                        console.log(res.errMsg);
                        console.log(res.errCode);
                    });
                })
            }
        }
    }
</script>
<style>
    .json {
        word-wrap: break-word;
    }
</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

ios:麦克风权限 adnorid:android.permission.RECORD_AUDIO

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问