cordova-plugin-media实现移动端录音功能
小编:管理员 396阅读 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进来的地方。它为网络应用和移动设备之间的连…
- Hibernate Criterion 在查询方法设计上能够灵活的依据Criteria的特点来方便地进行查询条件的组装.Hibernate设计了CriteriaSpecification作为Criteria的父接口,以下提供了Criteria和DetachedCriteria.Criteria和DetachedCriteria的主要差别在于创建的形式不一样,Criteria是在线的,所…