diff options
author | Sam Potts <me@sampotts.me> | 2018-01-05 10:37:38 +1100 |
---|---|---|
committer | Sam Potts <me@sampotts.me> | 2018-01-05 10:37:38 +1100 |
commit | e14e2cfaff8acb9a11719d8f5e5684ca7ff48a02 (patch) | |
tree | 71eba78d319de41582cd3ebbdb9c7acd88c09667 /src/js/ui.js | |
parent | 04119b27e69472cce70c7f5b5359c6b45ad718f9 (diff) | |
parent | 92cb9e22e24d52e1843a5865651f7b2c5a00d47a (diff) | |
download | plyr-e14e2cfaff8acb9a11719d8f5e5684ca7ff48a02.tar.lz plyr-e14e2cfaff8acb9a11719d8f5e5684ca7ff48a02.tar.xz plyr-e14e2cfaff8acb9a11719d8f5e5684ca7ff48a02.zip |
Merge branch 'develop' of https://github.com/Selz/plyr into develop
Diffstat (limited to 'src/js/ui.js')
-rw-r--r-- | src/js/ui.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/js/ui.js b/src/js/ui.js index 44f1a367..7a45a6c3 100644 --- a/src/js/ui.js +++ b/src/js/ui.js @@ -153,7 +153,7 @@ const ui = { // Check if media is loading checkLoading(event) { - this.loading = [ + this.loading = this.media.networkState === 2 || [ 'stalled', 'waiting', ].includes(event.type); @@ -171,6 +171,29 @@ const ui = { }, this.loading ? 250 : 0); }, + // Check if media failed to load + checkFailed() { + // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/networkState + this.failed = this.media.networkState === 3; + + if (this.failed) { + utils.toggleClass(this.elements.container, this.config.classNames.loading, false); + utils.toggleClass(this.elements.container, this.config.classNames.error, true); + } + + // Clear timer + clearTimeout(this.timers.failed); + + // Timer to prevent flicker when seeking + this.timers.loading = setTimeout(() => { + // Toggle container class hook + utils.toggleClass(this.elements.container, this.config.classNames.loading, this.loading); + + // Show controls if loading, hide if done + this.toggleControls(this.loading); + }, this.loading ? 250 : 0); + }, + // Update volume UI and storage updateVolume() { if (!this.supported.ui) { |