perf: 撤回语音消息时停止正在播放

This commit is contained in:
kuaifan 2022-05-29 10:36:46 +08:00
parent 939da1278f
commit 06951bbc29
3 changed files with 12 additions and 7 deletions

View File

@ -27,6 +27,7 @@ export default {
return {
audioSubscribe: null,
audioPlay: false,
audioId: 0,
audioSrc: null,
callback: null,
}
@ -48,19 +49,22 @@ export default {
}
},
methods: {
setAudioPlay(info) {
setAudioPlay(msg) {
const audio = this.$refs.audio;
const ended = audio.ended || audio.paused;
audio.controls = false;
audio.loop = false;
audio.volume = 1;
if (info === false) {
if (!ended) {
if (/\d+/.test(msg)) {
msg = msg == this.audioId
}
if (typeof msg === "boolean") {
if (!msg && !ended) {
audio.pause()
}
return
}
const {src, callback} = info
const {id, src, callback} = msg
this.callback = callback || null;
if (src === this.audioSrc) {
if (ended) {
@ -69,6 +73,7 @@ export default {
audio.pause();
}
} else {
this.audioId = id;
this.audioSrc = src;
if (!ended) {
audio.pause()

View File

@ -132,9 +132,7 @@ export default {
},
beforeDestroy() {
if (this.recordPlay) {
Store.set('audioSubscribe', false);
}
Store.set('audioSubscribe', this.msgData.id);
},
computed: {
@ -304,6 +302,7 @@ export default {
playRecord() {
Store.set('audioSubscribe', {
id: this.msgData.id,
src: this.msgData.msg.path,
callback: (play) => {
this.recordPlay = play;

View File

@ -2097,6 +2097,7 @@ export default {
ids.some(id => {
let index = state.dialogMsgs.findIndex(item => item.id == id);
if (index > -1) {
Store.set('audioSubscribe', id);
state.dialogMsgs.splice(index, 1);
}
})