|
@@ -53,7 +53,7 @@
|
|
|
<image :class="['img move2',recorderStatus==='doing'?'animat-run':'animat-pause']" src="./static/record-img.png" mode="widthFix" />
|
|
|
<image :class="['img move3',recorderStatus==='doing'?'animat-run':'animat-pause']" src="./static/record-img.png" mode="widthFix" />
|
|
|
</view>
|
|
|
- <view class="bot-text">{{time}}</view>
|
|
|
+ <view class="bot-text">{{time|formatTime}}</view>
|
|
|
</view>
|
|
|
|
|
|
<view class="sound-record-wrap" v-if="recorderStatus!=='stop'">
|
|
@@ -80,11 +80,12 @@
|
|
|
<script>
|
|
|
const recorderManager = wx.getRecorderManager();//录音实例
|
|
|
const innerAudioContext = uni.createInnerAudioContext();//播放音频实例
|
|
|
+let TIMER=null//计时器
|
|
|
export default {
|
|
|
filters:{
|
|
|
formatTime(e){
|
|
|
- let m=parseInt(e/60).toString()
|
|
|
- let s=parseInt(e%60).toString()
|
|
|
+ let m=parseInt(e/60)
|
|
|
+ let s=parseInt(e%60)
|
|
|
return `${m>9?m:'0'+m}:${s>9?s:'0'+s}`
|
|
|
}
|
|
|
},
|
|
@@ -109,7 +110,6 @@ export default {
|
|
|
|
|
|
recorderStatus:'start',//当前录音状态 start开始 doing正在录音 stop停止录音 pause录音暂停
|
|
|
time:0,
|
|
|
- timer:null,//计时器
|
|
|
isReset:false,//是否点击了重置
|
|
|
|
|
|
temAudio:{
|
|
@@ -138,25 +138,30 @@ export default {
|
|
|
console.log('开始录音');
|
|
|
this.recorderStatus='doing'
|
|
|
this.isReset=false
|
|
|
-
|
|
|
- this.timer=setInterval(() => {
|
|
|
- this.time++
|
|
|
- }, 1000);
|
|
|
+ if(!TIMER){
|
|
|
+ TIMER=setInterval(() => {
|
|
|
+ this.time++
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
})
|
|
|
recorderManager.onPause(()=>{
|
|
|
//录音暂停监听事件
|
|
|
console.log('录音暂停');
|
|
|
this.recorderStatus='pause'
|
|
|
- clearInterval(this.timer)
|
|
|
- this.timer=null
|
|
|
+ clearInterval(TIMER)
|
|
|
+ TIMER=null
|
|
|
})
|
|
|
recorderManager.onResume(()=>{
|
|
|
//录音继续监听事件
|
|
|
console.log('录音继续');
|
|
|
this.recorderStatus='doing'
|
|
|
- this.timer=setInterval(() => {
|
|
|
- this.time++
|
|
|
- }, 1000);
|
|
|
+
|
|
|
+ if(!TIMER){
|
|
|
+ TIMER=setInterval(() => {
|
|
|
+ this.time++
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
})
|
|
|
recorderManager.onStop((e)=>{
|
|
|
//录音结束监听事件
|
|
@@ -170,8 +175,8 @@ export default {
|
|
|
this.temAudio.duration=parseInt(e.duration/1000)
|
|
|
}
|
|
|
|
|
|
- clearInterval(this.timer)
|
|
|
- this.timer=null
|
|
|
+ clearInterval(TIMER)
|
|
|
+ TIMER=null
|
|
|
})
|
|
|
recorderManager.onError((e)=>{
|
|
|
//录音事件错误监听
|
|
@@ -252,7 +257,6 @@ export default {
|
|
|
innerAudioContext.src=''
|
|
|
})
|
|
|
innerAudioContext.onTimeUpdate(()=>{
|
|
|
- console.log(innerAudioContext.currentTime);
|
|
|
this.temAudio.curTime=parseInt(innerAudioContext.currentTime)
|
|
|
})
|
|
|
},
|
|
@@ -262,6 +266,8 @@ export default {
|
|
|
this.recorderStatus='start'
|
|
|
this.isReset=true
|
|
|
this.temAudio.url=''
|
|
|
+ this.time=0
|
|
|
+ TIMER=null
|
|
|
}
|
|
|
|
|
|
},
|