cordova plugin add cordova-plugin-media-captureaudioCapture(){
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);
},原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。