Avoid duplicated code

This commit is contained in:
mfcar 2024-05-04 11:17:41 +01:00
parent b37a863c0a
commit 8e5fc4a411
No known key found for this signature in database

View file

@ -138,17 +138,7 @@ export default class LocalAudioPlayer extends EventEmitter {
this.player.src = this.currentTrack.relativeContentUrl this.player.src = this.currentTrack.relativeContentUrl
this.player.currentTime = this.startTime this.player.currentTime = this.startTime
if (document.getElementById('transcription-track')) { this.createTranscriptionTrack();
document.getElementById('transcription-track').remove()
}
const trackElement = document.createElement("track");
trackElement.id = "transcription-track";
trackElement.kind = "subtitles";
trackElement.label = "Transcription";
trackElement.default = true;
trackElement.src = this.currentTrack.relativeTranscriptionUrl;
this.player.appendChild(trackElement);
return return
} }
@ -221,8 +211,14 @@ export default class LocalAudioPlayer extends EventEmitter {
this.player.src = this.currentTrack.relativeContentUrl this.player.src = this.currentTrack.relativeContentUrl
console.log(`[LocalPlayer] Loading track src ${this.currentTrack.relativeContentUrl}`) console.log(`[LocalPlayer] Loading track src ${this.currentTrack.relativeContentUrl}`)
this.createTranscriptionTrack();
this.player.load()
}
createTranscriptionTrack() {
if (document.getElementById('transcription-track')) { if (document.getElementById('transcription-track')) {
document.getElementById('transcription-track').remove() document.getElementById('transcription-track').remove();
} }
const trackElement = document.createElement("track"); const trackElement = document.createElement("track");
@ -232,8 +228,6 @@ export default class LocalAudioPlayer extends EventEmitter {
trackElement.default = true; trackElement.default = true;
trackElement.src = this.currentTrack.relativeTranscriptionUrl; trackElement.src = this.currentTrack.relativeTranscriptionUrl;
this.player.appendChild(trackElement); this.player.appendChild(trackElement);
this.player.load()
} }
destroyHlsInstance() { destroyHlsInstance() {