(fix) reload sound in <PronunciationSpeaker> if an error occured or the input changed

This commit is contained in:
Valentyne Stigloher 2024-01-29 15:33:50 +01:00
parent 760636ad2f
commit c0a4c41d4b

View File

@ -64,7 +64,8 @@ export default {
}, },
methods: { methods: {
pronounce() { pronounce() {
if (this.sound) { if (this.sound && this.sound.src.endsWith(this.pronunciationLink) && !this.sound.error) {
// reuse the sound object if it has the same source and has been loaded without an error
this.sound.pause(); this.sound.pause();
this.sound.currentTime = 0; this.sound.currentTime = 0;
this.sound.play(); this.sound.play();
@ -74,7 +75,7 @@ export default {
this.sound = new Audio(this.pronunciationLink); this.sound = new Audio(this.pronunciationLink);
this.sound.addEventListener('loadeddata', () => this.sound.play()); this.sound.addEventListener('canplay', () => this.sound.play());
this.sound.addEventListener('play', () => this.state = STATE_PLAYING); this.sound.addEventListener('play', () => this.state = STATE_PLAYING);
this.sound.addEventListener('ended', () => this.state = STATE_IDLE); this.sound.addEventListener('ended', () => this.state = STATE_IDLE);
this.sound.addEventListener('error', () => this.state = STATE_IDLE); this.sound.addEventListener('error', () => this.state = STATE_IDLE);