From f016a367b53f8b835fa3440aae34928246f6f253 Mon Sep 17 00:00:00 2001 From: "Emilis (Idea IT)" <78907189+emilis-ideait@users.noreply.github.com> Date: Tue, 24 Aug 2021 15:24:50 +0300 Subject: [PATCH] Fixed errors when Plyr instance is destroyed before constructor setTimeout() functions execute. (#2108) Co-authored-by: Emilis Dambauskas --- src/js/captions.js | 4 +++- src/js/plyr.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/js/captions.js b/src/js/captions.js index 98d7d613..856baccf 100644 --- a/src/js/captions.js +++ b/src/js/captions.js @@ -154,7 +154,9 @@ const captions = { } // Enable or disable captions based on track length - toggleClass(this.elements.container, this.config.classNames.captions.enabled, !is.empty(tracks)); + if (this.elements) { + toggleClass(this.elements.container, this.config.classNames.captions.enabled, !is.empty(tracks)); + } // Update available languages in list if ( diff --git a/src/js/plyr.js b/src/js/plyr.js index faf3ac0d..696acca5 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -675,7 +675,9 @@ class Plyr { // Set media speed setTimeout(() => { - this.media.playbackRate = speed; + if (this.media) { + this.media.playbackRate = speed; + } }, 0); }