From 17e443fdeb80d9503fd4709a656b9ef749a9287c Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 22 Feb 2022 17:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=8F=91=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E8=AF=AD=E9=9F=B3=E6=92=AD=E6=94=BE=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E4=BB=8E=E8=BF=9C=E7=AB=AF=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=88=B0=E6=9C=AC=E5=9C=B0=E4=B9=8B=E5=90=8E=E5=86=8D=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=B0=B1=E5=A5=BD=E4=BA=86=EF=BC=8C=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E5=8D=87=E7=BA=A7=EF=BC=8C=E5=8F=91=E5=B8=83demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 4 +- pages/im/components/show/showVoice.vue | 117 +++++++++++++------------ 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/manifest.json b/manifest.json index a3dbfea..ffbf6c3 100644 --- a/manifest.json +++ b/manifest.json @@ -2,8 +2,8 @@ "name" : "ZH-HEALTH", "appid" : "__UNI__C29473D", "description" : "ZH-HEALTH,您手上的健康管理专家", - "versionName" : "1.0.11", - "versionCode" : 111, + "versionName" : "1.0.13", + "versionCode" : 113, "transformPx" : false, /* 5+App特有相关 */ "app-plus" : { diff --git a/pages/im/components/show/showVoice.vue b/pages/im/components/show/showVoice.vue index 7f6fafc..0349c8d 100644 --- a/pages/im/components/show/showVoice.vue +++ b/pages/im/components/show/showVoice.vue @@ -2,9 +2,12 @@ {{ contact(message.senderUserId).name }} - - - + + + {{ duration }}" @@ -27,13 +30,13 @@ isGroup: { type: Boolean, default: false - } + } }, data() { return { onPlay: false, - innerAC: null, - msgId : null + innerAC: null, + msgId: null } }, computed: { @@ -47,13 +50,13 @@ return function(targetId) { return this.$store.getters.contactInfo(targetId) } - }, - width() { - if (this.duration > 3) { - return (this.duration * 5) + 150 - } else { - return 120 - } + }, + width() { + if (this.duration > 3) { + return (this.duration * 5) + 150 + } else { + return 120 + } } }, mounted() { @@ -63,12 +66,12 @@ this.stopPlay() } }) - }, - - created() { - console.log(this.message.messageId) - }, - + }, + + created() { + console.log(this.message.messageId) + }, + methods: { // 播放语音消息 startPlay() { @@ -76,9 +79,10 @@ if (this.onPlay) { this.stopPlay() return - } + } + this.onPlay = true // 如果下载到了本地,那么直接播放,否则调用下载语音消息接口,下载后再播放 - if (this.message.content.local) { + if (this.message.content.local && this.message.content.local.indexOf('///data/user/') < 0) { this.playVoice(this.message.content.local) } else { RongIMLib.downloadMediaMessage(this.message.messageId, { @@ -88,27 +92,27 @@ }, progress: (progress, messageId) => {}, cancel: (messageId) => {}, - error: (errorCode, messageId) => { - uni.showToast({ - icon: 'none', - title: '语音播放失败' - }) + error: (errorCode, messageId) => { + uni.showToast({ + icon: 'none', + title: '语音播放失败' + }) } }) } }, - playVoice(path) { + playVoice(path) { console.log('准备播放', this.message.content); this.innerAC = uni.createInnerAudioContext() this.innerAC.src = path - this.innerAC.autoplay = false - this.msgId = this.message.messageId - this.innerAC.onCanplay(res => { + this.innerAC.autoplay = false + this.msgId = this.message.messageId + this.innerAC.onCanplay(res => { + console.log('onCanplay') this.innerAC.play() - }) - - this.innerAC.onPlay(res => { - this.onPlay = true + }) + this.innerAC.onPlay(res => { + console.log('onPlay') uni.$emit('onVoiceMessagePlay', this.message.messageId) }) this.innerAC.onEnded(res => { @@ -117,11 +121,11 @@ this.innerAC.onStop(() => { this.onPlay = false this.innerAC.destroy() - this.innerAC = null - this.msgId = 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: '语音播放失败' @@ -129,31 +133,32 @@ }) }, stopPlay() { - // 停止播放语音消息 if (this.innerAC) { this.innerAC.stop() } } } } - - -