Add disposal to audio switcher

This commit is contained in:
Xaekai 2022-02-12 19:40:51 -08:00 committed by Calvin Montgomery
parent 008c24f892
commit 2cf26cdc4c
1 changed files with 8 additions and 1 deletions

View File

@ -477,7 +477,7 @@
audio.currentTime = time; audio.currentTime = time;
}; };
function audioSwitchPlugin(options) { function audioSwitchPlugin(options) {
const {audioElement, audioTracks, debugInterval, syncInterval, volume} = options; const {audioElement, audioTracks, debugInterval, syncInterval, volume, handleDisposal} = options;
const player = this; const player = this;
const checkAudioElement = () => { const checkAudioElement = () => {
const videoElement = player.el_; const videoElement = player.el_;
@ -533,6 +533,13 @@
audioTracks.forEach(track => audioTrackList.addTrack(new videojs.AudioTrack(track))); audioTracks.forEach(track => audioTrackList.addTrack(new videojs.AudioTrack(track)));
audio.setAttribute('src', audioTracks[0].url); audio.setAttribute('src', audioTracks[0].url);
} }
player.on('dispose', () => {
this.audio.pause();
if(this.isOurAudio || handleDisposal){
this.audio.remove();
this.audioParent.remove();
}
});
player.on('play', () => { player.on('play', () => {
syncTime(player, audio); syncTime(player, audio);
if (audio.paused) if (audio.paused)