Browse Source

录音授权问题

cxmo 2 years ago
parent
commit
07a286eff3
1 changed files with 45 additions and 8 deletions
  1. 45 8
      pages-question/answerDetail.vue

+ 45 - 8
pages-question/answerDetail.vue

@@ -208,11 +208,11 @@ export default {
       timer: null,
       audioItem: null,
       pageLoading: false,
-      isPlayed: false, //拖动进度条前音频是否为播放状态
       playIconKey: 0,
       isplay: false,
       isSlider: false,
       scrollTop:0,
+      isStart:false,//判断录音是否开始
     };
   },
   onLoad(options) {
@@ -269,6 +269,7 @@ export default {
     handleRecorderFun() {
       this.globalRecorder.onStart(() => {
         console.log("开始录音");
+        uni.hideToast();
         this.clockTime();
       });
       this.globalRecorder.onPause(() => {
@@ -297,7 +298,14 @@ export default {
         this.pageLoading = false;
       });
       this.globalRecorder.onError((res) => {
-        console.log("err", res);
+        uni.showToast({
+          title:res.errMsg,
+          icon:'none'
+        })
+        //开始录音失败
+        if(res.errMsg.includes('start')){
+          this.questionItem.recordStatus = 1;
+        }
       });
       /* this.globalRecorder.onFrameRecorded((res) => {
         console.log("?", res);
@@ -354,19 +362,24 @@ export default {
       console.log('a',this.questionItem.recordStatus)
       //根据questionItem.recordStatus
       if (this.questionItem.recordStatus === 1) {
-        //开始录音
-        this.globalRecorder.start({ duration: 180000, format: "mp3" });
-        //this.clockTime();
-        this.questionItem.recordStatus = 2;
+        const that = this
+        //检查是否有权限
+        uni.getSetting({
+          success(res){
+            if(res.authSetting['scope.record']){
+              that.startRecord()
+            }else{
+              that.getRecordAuth()
+            }
+          }
+        });
       } else if (this.questionItem.recordStatus === 2) {
         //暂停录音
         this.globalRecorder.pause();
-        //this.cleanTime();
         this.questionItem.recordStatus = 3;
       } else if (this.questionItem.recordStatus === 3) {
         //继续录音
         this.globalRecorder.resume();
-        this.clockTime();
         this.questionItem.recordStatus = 2;
       } else {
         //结束录音
@@ -374,6 +387,29 @@ export default {
         //this.cleanTime();
       }
     },
+    //获取录音授权
+    getRecordAuth(){
+      const {community_question_id} = this.questionItem
+      uni.openSetting({
+        success(res){
+          //刷新页面
+          if(res.authSetting['scope.record']){
+            uni.redirectTo({url: `/pages-question/answerDetail?id=${community_question_id}`})
+          }
+        }
+      })
+      //this.questionItem.recordStatus = 1
+    },
+    //开启录音
+    startRecord(){
+      console.log(this.globalRecorder)
+      this.globalRecorder.start({ duration: 180000, format: "mp3" });
+      uni.showToast({
+        title:'加载中',
+        icon:'loading'
+      })
+      this.questionItem.recordStatus = 2;
+    },
     //上传音频
     async uploadAudio() {
       const res = await uploadAudioToServer(this.innerAudio.src);
@@ -548,6 +584,7 @@ export default {
         text-align: center;
         color: #999999ff;
         font-size: 28rpx;
+        height:130rpx;
         image {
           width: 94rpx;
         }