黑色领带结
黑色领带结
  • 发布:2021-03-29 11:48
  • 更新:2022-02-07 15:58
  • 阅读:955

录音 recorderManager.onStop 部分安卓机型

分类:uni-app

小米11青春版
miui12.5
安卓11
ios上可以执行
安卓 console.log('recorder stop' + JSON.stringify(res)); 无打印

touchend和touchcancel 也无法执行
现在注释掉了

<template>  
    <view class="audioPlay">  
        <button @click="startRecord">开始录音</button>  
        <button @click="endRecord">停止录音</button>  
         <!-- <button @touchstart="startRecord" @touchend="endRecord">按住说话,松开结束</button> -->  
        <button @tap="playVoice">播放录音</button>  
        <view class="status">录音中{{intIntervalTime}}s>>></view>  
    </view>  
</template>  
<script>  
    const recorderManager = uni.getRecorderManager();  
    const innerAudioContext = uni.createInnerAudioContext();  
    innerAudioContext.autoplay = true;  
    export default {  
        data() {  
            return {  
                recorderManager: {},  
                innerAudioContext: {},  
                voicePath: '',  
                intervalTime: 0,  
                isRecord:false  
            }  
        },  
        onLoad() {  

            let self = this;  
            recorderManager.onStop(function (res) {  
                console.log('recorder stop' + JSON.stringify(res));  
                self.voicePath = res.tempFilePath;  
            });  
            },  
             computed: {  
                intIntervalTime() {  
                  // 用于显示整数的秒数  

                  console.log(Math.round(this.intervalTime));  

                  return Math.round(this.intervalTime);  
                }  
              },  
            methods: {  
                startRecord() {  
                   this.timer = setInterval(() => {  
                          this.intervalTime += 0.5;  
                          if (this.intervalTime >= 0.5 && !this.isRecord) {  
                            //如果用户录制的时间太短,就不会去开启录音, 因为有个bug: recorderManager.stop()在短时间内开启在关闭的话,实际上他还在不停地录音,不知道你们有没有遇到过  

                            console.log("开始录音");  

                            this.isRecord = true;  

                            this.intervalTime = 0;  

                            recorderManager.start({  
                              format: "mp3"  
                            });  
                          }  
                        }, 500);  
                },  
                endRecord() {  
                    if (this.intervalTime <= 0.5) {  
                           console.log("录音太短了!!!");  
                         }  

                         clearInterval(this.timer);  

                         if (this.isRecord) {  
                           setTimeout(() => {  
                             recorderManager.stop();  

                             this.isRecord = false;  

                             console.log(this.isRecord);  
                           }, 500); //延迟小段时间停止录音, 更好的体验  
                         }  
                },  
                playVoice() {  
                    console.log('播放录音');  
                    if (this.voicePath) {  
                        innerAudioContext.src = this.voicePath;  
                        innerAudioContext.play();  
                    }  
                }  
            }  
    }  
</script>  

<style>  
.audioPlay{  
    margin-top: 500rpx;  
}  
</style>  
2021-03-29 11:48 负责人:无 分享
已邀请:
忆夕语

忆夕语

请问一下这个问题最后如何解决的呢?

凯茵化工

凯茵化工

都2022了,长按后touchend和touchcancel不触发的问题还没解决?

该问题目前已经被锁定, 无法添加新回复