Started on error handling

This commit is contained in:
Sam
2018-01-04 13:43:56 +11:00
parent 6b9106ddb1
commit 92cb9e22e2
16 changed files with 84 additions and 12 deletions

View File

@ -305,6 +305,7 @@ const defaults = {
stopped: 'plyr--stopped',
playing: 'plyr--playing',
loading: 'plyr--loading',
error: 'plyr--has-error',
hover: 'plyr--hover',
tooltip: 'plyr__tooltip',
hidden: 'plyr__sr-only',

View File

@ -221,6 +221,11 @@ const listeners = {
utils.on(document, fullscreen.eventType, event => {
this.toggleFullscreen(event);
});
// Fullscreen toggle on double click
utils.on(this.elements.container, 'dblclick', event => {
this.toggleFullscreen(event);
});
}
},
@ -263,6 +268,9 @@ const listeners = {
// Loading
utils.on(this.media, 'stalled waiting canplay seeked playing', event => ui.checkLoading.call(this, event));
// Check if media failed to load
// utils.on(this.media, 'play', event => ui.checkFailed.call(this, event));
// Click video
if (this.supported.ui && this.config.clickToPlay && !this.isAudio) {
// Re-fetch the wrapper

View File

@ -35,7 +35,11 @@ let scrollPosition = {
class Plyr {
constructor(target, options) {
this.timers = {};
// State
this.ready = false;
this.loading = false;
this.failed = false;
// Set the media element
this.media = target;
@ -809,6 +813,11 @@ class Plyr {
* @param {event} event
*/
toggleFullscreen(event) {
// Video only
if (this.isAudio) {
return;
}
// Check for native support
if (fullscreen.enabled) {
if (utils.is.event(event) && event.type === fullscreen.eventType) {

View File

@ -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) {