uniapp:钉钉小程序需要录音权限及调用录音

bash 复制代码
{
    // ... 其他配置项
    "mp-dingtalk": {
        "permission": {
             "scope.userLocation" : {
                "desc" : "系统希望获得您的定位用于确认您周围的设施数据"
            },
            "scope.bluetooth" : {
                "desc" : "你的蓝牙权限将用于小程序搜索打印机、连接打印机、打印相关功能"
            },
			"microphone" : {
			    "desc" : "录音功能需要麦克风权限"
			}
            // ... 其他权限配置
        }
        // ... 其他dring配置
    }
    // ... 其他配置项
}
TypeScript 复制代码
mounted() {
	if (dd.canIUse('getRecorderManager')) { // 端上支持
		this.recorderManager = dd.getRecorderManager()
	} else { // 端上不支持
		dd.alert({
			content: '请升级钉钉版本至7.0.10以支持录音功能'
		})
	}
	this.audioManager = uni.getBackgroundAudioManager();
},
TypeScript 复制代码
const recorderManager = uni.getRecorderManager();
 
recorderManager.start({
    duration: 60000, // 录音的最大时长,单位 ms
    sampleRate: 16000, // 采样率
    numberOfChannels: 1, // 录音通道数
    encodeBitRate: 96000, // 编码码率
    format: 'aac' // 音频格式,只在mp3格式下有效,是否调用getFrameBuffer
});
 
############### 编译钉钉会找不到对应方法 #####################

recorderManager.onStart(() => {
    console.log('录音开始');
});
 
recorderManager.onStop((res) => {
    console.log('录音结束', res);
    const { tempFilePath } = res;
    // 处理录音文件...
});

recorderManager.onError((error) => {
    console.error('录音错误', error);
});
 
############### 编译钉钉会找不到对应方法 #####################

 
############### 调用正确 #####################

recorderManager.onstart = (res) => {
    console.log('录音开始');
}
 
recorderManager.onstop = (res) => {
    console.log('录音结束', res);
    const { tempFilePath } = res;
    // 处理录音文件...
}

recorderManager.onerror = (err) => {
    console.error('录音错误', err);
};
 
############### 调用正确 #####################
 
// 停止录音
recorderManager.stop();

由于在uniapp中使用长按事件,编译钉钉小程序后无效,所以只能使用click事件声明一个字段来判断长按松开~~~~

如果过程中,录音之后无响应,使用onerror打印错误:

一般是遇到文件无法保存的问题,直接真机测试就没有问题了~~~

相关推荐
不如摸鱼去16 小时前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
微信小程序·小程序·uni-app·aigc·ai编程
小白_ysf21 小时前
uniapp 开发微信小程序,获取经纬度并且转化详细地址(单独封装版本)
微信小程序·uni-app
iOS阿玮1 天前
三年期已满,你的产品不再更新将于90天后下架。
uni-app·app·apple
weixin_lynhgworld1 天前
剧本杀小程序系统开发:构建剧本杀社交新生态
小程序
说私域1 天前
基于定制开发开源 AI 智能名片 S2B2C 商城小程序的热点与人工下发策略研究
人工智能·小程序
weixin_lynhgworld1 天前
陪诊小程序系统开发:让就医不再是一件难事
小程序
bug总结2 天前
深入理解 uni-app 的 uni.createSelectorQuery()
uni-app
weixin_lynhgworld2 天前
盲盒抽谷机小程序系统开发:从0到1的完整方法论
小程序
weixin_lynhgworld2 天前
短剧小程序系统开发:赋能创作者,推动短剧艺术创新发展
小程序
真上帝的左手2 天前
25. 移动端-uni-app
uni-app