1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| <script> const frontservice = uni.requireNativePlugin('zjw-frontservice'); const recorderManager = uni.getRecorderManager(); const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
export default { data() { return { voicePath: '', }; }, onLoad() { let self = this; recorderManager.onStop(function (res) { console.log('recorder stop' + JSON.stringify(res)); self.voicePath = res.tempFilePath; }); }, methods: { stop() { frontservice.stop({}, (result) => { modal.toast({ message: 'closed', duration: 1.5, }); }); }, start() { frontservice.start( { title: '请不要关闭此固定通知栏', content: '正在定位...', delaysec: 2000, isIgnoringBattery: false, //不开启电池优化 }, (result) => { console.log(result); // 录音代码 this.startRecord(); } ); }, startRecord() { // 授权录音权限 let env = uni.getSystemInfoSync().platform; permision .requestAndroidPermission('android.permission.RECORD_AUDIO') .then((e) => { if (e === -1) { uni.showToast({ title: '您已经永久拒绝录音权限,请在应用设置中手动打开', icon: 'none', }); } else if (e === 0) { uni.showToast({ title: '您拒绝了录音授权', icon: 'none', }); } else if (e === 1) { this.show = true; console.log('开始录音');
recorderManager.start();
console.log('开始定位'); uni.getLocation({ type: 'wgs84', success: function (res) { console.log('当前位置的经度:' + res.longitude); console.log('当前位置的纬度:' + res.latitude); } }); } else { uni.showToast({ title: '授权返回值错误', icon: 'none', }); } }) .catch((err) => { uni.showToast({ title: '拉起录音授权失败', icon: 'none', }); }); }, // 上传录音文件 uploadRecord() { uni.showLoading(); uni.uploadFile({ url, '地址', filePath: this.voicePath, //录音结束后返回的临时路径 name: 'file', // 文件对应的 key值对象名称 header: { 'Content-Type': 'multipart/form-data', token: 'token', //token信息 }, success: (res) => { uni.hideLoading(); console.log('result', result); }, fail: (res) => { uni.hideLoading(); uni.showToast({ title: '失败', icon: 'none', }); }, }); }, }, }; </script>
|