cordova-plugin-media实现移动端录音功能
小编:管理员 913阅读 2022.09.13
安装插件
cordova plugin add cordova-plugin-media-capture复制移动端方法调取手机录音
audioCapture(){ navigator.device.audiorecorder.recordAudio(this.successCallback, this.errorCallback, 60); },复制
成功回调方法:
successCallback(data){ this.filename = JSON.parse(data).file_name; this.upload4audio(JSON.parse(data).full_path); },复制拿到录音在本地的保存文件直接上传至服务器
//使用FileTransfer插件,上传文件------语音文件 upload4audio(fileURL) { var _this = this; //上传成功 var success = function (r) { var strs = JSON.parse(r.response); _this.audiopath = JSON.parse(r.response).data.audioShowUrl; _this.content = _this.audiopath; _this.msgtype = 2; _this.action_type = 'send_msg'; _this.send2Server(); _this.getHeight(); _this.message = ''; } //上传失败 var fail = function (error) { var str = JSON.stringify(error); alert("转码失败请重试!"+str) } var options = new FileUploadOptions(); options.fileKey = "file1"; options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1); //上传参数 var params = {}; params.value1 = "test"; params.value2 = "param"; options.params = params; var ft = new FileTransfer(); //上传地址 var SERVER = "http://81.68.107.23/api/upload/upload4audio" ft.upload(fileURL, encodeURI(SERVER), success, fail, options); },复制
相关推荐
- Cordova 什么是Cordova? Cordova是用于使用HTML,CSS和JS构建移动应用的平台。我们可以认为Cordova是一个容器,用于将我们的网络应用程序与本机移动功能连接。默认情况下,Web应用程序不能使用本机移动功能。这就是Cordova进来的地方。它为网络应用和移动设备之间的连…
- 3DMAX提示和技巧 本主题标识使用 Civil View 的一些重要提示和技巧。常规使用屏幕分辨率至少为 1280x1024 的 Civil View。低于此分辨率时,一些面板将占用过多屏幕空间。 将视口设置为线框显示以达到最佳性能。 要尽可能简化用户界面,请在单个视口中工作并关闭 3ds Max 命令面…