cordova-plugin-media實現移動端錄音功能
小編:管理員 812閱讀 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使用“材質資源管理器”的“場景”面板管理材質 要更改材質分配,請執行以下操作之一:將“材質資源管理器”的“場景”面板中材質的縮略圖或圖標(位于材質名稱的左側)拖動到視口中的某個對象上。 選擇多個對象,然后將“材質資源管理器”的“場景”面板中材質的縮略圖或圖標(位于材質名稱的左側)拖動到其…