This commit is contained in:
2022-02-22 16:51:20 +08:00
13 changed files with 178 additions and 101 deletions

View File

@@ -3,8 +3,8 @@
<view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
<view class="msg--voice">
<view :class="['voice', isRemote ? 'left': 'right', {'onPlay': onPlay}]" :style="{width: width + 'rpx'}" @click="startPlay">
<image v-if="isRemote" class="icon" src="@/static/icon/audio_green.png" mode="widthFix"></image>
<image v-else class="icon" src="@/static/icon/audio_white.png" mode="widthFix"></image>
<image v-if="isRemote" class="icon" :class="{ 'videoFlicker' : onPlay && msgId == message.messageId }" src="@/static/icon/audio_green.png" mode="widthFix"></image>
<image v-else class="icon" :class="{ 'videoFlicker' : onPlay && msgId == message.messageId }" src="@/static/icon/audio_white.png" mode="widthFix"></image>
<text class="duration">{{ duration }}"</text>
</view>
<u-badge isDot :show="message.content.local =='' && isRemote" />
@@ -27,12 +27,13 @@
isGroup: {
type: Boolean,
default: false
}
}
},
data() {
return {
onPlay: false,
innerAC: null,
msgId : null
}
},
computed: {
@@ -62,7 +63,12 @@
this.stopPlay()
}
})
},
},
created() {
console.log(this.message.messageId)
},
methods: {
// 播放语音消息
startPlay() {
@@ -91,15 +97,17 @@
})
}
},
playVoice(path) {
playVoice(path) {
console.log('准备播放', this.message.content);
this.innerAC = uni.createInnerAudioContext()
this.innerAC.src = path
this.innerAC.autoplay = false
this.innerAC.onCanplay(res => {
this.innerAC.autoplay = false
this.msgId = this.message.messageId
this.innerAC.onCanplay(res => {
this.innerAC.play()
})
this.innerAC.onPlay(res => {
})
this.innerAC.onPlay(res => {
this.onPlay = true
uni.$emit('onVoiceMessagePlay', this.message.messageId)
})
@@ -109,10 +117,11 @@
this.innerAC.onStop(() => {
this.onPlay = false
this.innerAC.destroy()
this.innerAC = null
this.innerAC = null
this.msgId = null
uni.$emit('onVoiceMessageStop', this.message.messageId)
})
this.innerAC.onError(err => {
this.innerAC.onError(err => {
uni.showToast({
icon: 'none',
title: '语音播放失败'
@@ -127,7 +136,25 @@
}
}
}
</script>
</script>
<style>
@keyframes playFlicker{
0%{
opacity: 1;
}
50%{
opacity: .5;
}
100%{
opacity: 1;
}
}
.videoFlicker{
animation: playFlicker 1s infinite;
}
</style>
<style scoped lang="scss">
.name {