Fix playback bug on first load

Also, don't replay our own messages when just sent.
This commit is contained in:
N-Pex 2023-02-17 17:20:26 +01:00 committed by n8fr8
parent db3679a91c
commit 3853f21f90

View file

@ -98,8 +98,26 @@ export default {
document.body.classList.add("dark"); document.body.classList.add("dark");
this.$root.$on('playback-start', this.onPlaybackStart); this.$root.$on('playback-start', this.onPlaybackStart);
this.player = this.$refs.player; this.player = this.$refs.player;
this.player.autoplay = false;
this.player.addEventListener("timeupdate", this.updateProgressBar); this.player.addEventListener("timeupdate", this.updateProgressBar);
this.player.addEventListener("play", () => { this.player.addEventListener("play", () => {
if (!this.analyser) {
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
let audioSource = null;
if (audioCtx) {
audioSource = audioCtx.createMediaElementSource(this.player);
this.analyser = audioCtx.createAnalyser();
audioSource.connect(this.analyser);
this.analyser.connect(audioCtx.destination);
this.analyser.fftSize = 128;
const bufferLength = this.analyser.frequencyBinCount;
this.analyzerDataArray = new Uint8Array(bufferLength);
}
}
this.playing = true; this.playing = true;
this.updateVisualization(); this.updateVisualization();
if (this.currentAudioEvent) { if (this.currentAudioEvent) {
@ -116,19 +134,6 @@ export default {
this.clearVisualization(); this.clearVisualization();
this.onPlaybackEnd(); this.onPlaybackEnd();
}); });
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
let audioSource = null;
if (audioCtx) {
audioSource = audioCtx.createMediaElementSource(this.player);
this.analyser = audioCtx.createAnalyser();
audioSource.connect(this.analyser);
this.analyser.connect(audioCtx.destination);
this.analyser.fftSize = 128;
const bufferLength = this.analyser.frequencyBinCount;
this.analyzerDataArray = new Uint8Array(bufferLength);
}
}, },
beforeDestroy() { beforeDestroy() {
document.body.classList.remove("dark"); document.body.classList.remove("dark");
@ -204,7 +209,17 @@ export default {
return; return;
} }
this.src = null; this.src = null;
const autoPlayWasSet = this.autoPlayNextEvent;
this.autoPlayNextEvent = false; this.autoPlayNextEvent = false;
if (value.getSender() == this.$matrix.currentUserId) {
// Sent by us. Don't autoplay if we just sent this (i.e. it is ahead of our read marker)
if (this.room && !this.room.getReceiptsForEvent(value).includes(value.getSender())) {
this.player.autoplay = false;
this.autoPlayNextEvent = autoPlayWasSet;
}
}
this.loadAudioAttachmentSource(); this.loadAudioAttachmentSource();
} }
}, },