Started on error handling, Safari icon fix
This commit is contained in:
9
src/js/controls.js
vendored
9
src/js/controls.js
vendored
@ -75,14 +75,11 @@ const controls = {
|
||||
const use = document.createElementNS(namespace, 'use');
|
||||
const path = `${iconPath}-${type}`;
|
||||
|
||||
// If the new `href` attribute is supported, use that
|
||||
// Set `href` attributes
|
||||
// https://github.com/sampotts/plyr/issues/460
|
||||
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href
|
||||
if ('href' in use) {
|
||||
use.setAttribute('href', path);
|
||||
} else {
|
||||
use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', path);
|
||||
}
|
||||
use.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
|
||||
use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', path);
|
||||
|
||||
// Add <use> to <svg>
|
||||
icon.appendChild(use);
|
||||
|
@ -341,7 +341,14 @@ const listeners = {
|
||||
// Proxy events to container
|
||||
// Bubble up key events for Edge
|
||||
utils.on(this.media, this.config.events.concat(['keyup', 'keydown']).join(' '), event => {
|
||||
utils.dispatchEvent.call(this, this.elements.container, event.type, true);
|
||||
let detail = {};
|
||||
|
||||
// Get error details from media
|
||||
if (event.type === 'error') {
|
||||
detail = this.media.error;
|
||||
}
|
||||
|
||||
utils.dispatchEvent.call(this, this.elements.container, event.type, true, detail);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -37,7 +37,8 @@ const vimeo = {
|
||||
setAspectRatio(input) {
|
||||
const ratio = utils.is.string(input) ? input.split(':') : this.config.ratio.split(':');
|
||||
const padding = 100 / ratio[0] * ratio[1];
|
||||
const offset = (300 - padding) / 6;
|
||||
const height = 200;
|
||||
const offset = (height - padding) / (height / 50);
|
||||
this.elements.wrapper.style.paddingBottom = `${padding}%`;
|
||||
this.media.style.transform = `translateY(-${offset}%)`;
|
||||
},
|
||||
@ -70,23 +71,27 @@ const vimeo = {
|
||||
// https://github.com/vimeo/player.js
|
||||
player.embed = new window.Vimeo.Player(iframe);
|
||||
|
||||
// Create a faux HTML5 API using the Vimeo API
|
||||
player.media.play = () => {
|
||||
player.embed.play();
|
||||
player.media.paused = false;
|
||||
};
|
||||
player.media.pause = () => {
|
||||
player.embed.pause();
|
||||
player.media.paused = true;
|
||||
};
|
||||
player.media.stop = () => {
|
||||
player.embed.stop();
|
||||
player.media.paused = true;
|
||||
};
|
||||
|
||||
player.media.paused = true;
|
||||
player.media.currentTime = 0;
|
||||
|
||||
// Create a faux HTML5 API using the Vimeo API
|
||||
player.media.play = () => {
|
||||
player.embed.play().then(() => {
|
||||
player.media.paused = false;
|
||||
});
|
||||
};
|
||||
player.media.pause = () => {
|
||||
player.embed.pause().then(() => {
|
||||
player.media.paused = true;
|
||||
});
|
||||
};
|
||||
player.media.stop = () => {
|
||||
player.embed.stop().then(() => {
|
||||
player.media.paused = true;
|
||||
player.currentTime = 0;
|
||||
});
|
||||
};
|
||||
|
||||
// Seeking
|
||||
let { currentTime } = player.media;
|
||||
Object.defineProperty(player.media, 'currentTime', {
|
||||
@ -121,9 +126,10 @@ const vimeo = {
|
||||
return speed;
|
||||
},
|
||||
set(input) {
|
||||
speed = input;
|
||||
player.embed.setPlaybackRate(input);
|
||||
utils.dispatchEvent.call(player, player.media, 'ratechange');
|
||||
player.embed.setPlaybackRate(input).then(() => {
|
||||
speed = input;
|
||||
utils.dispatchEvent.call(player, player.media, 'ratechange');
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@ -134,9 +140,10 @@ const vimeo = {
|
||||
return volume;
|
||||
},
|
||||
set(input) {
|
||||
volume = input;
|
||||
player.embed.setVolume(input);
|
||||
utils.dispatchEvent.call(player, player.media, 'volumechange');
|
||||
player.embed.setVolume(input).then(() => {
|
||||
volume = input;
|
||||
utils.dispatchEvent.call(player, player.media, 'volumechange');
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@ -148,9 +155,11 @@ const vimeo = {
|
||||
},
|
||||
set(input) {
|
||||
const toggle = utils.is.boolean(input) ? input : false;
|
||||
muted = toggle;
|
||||
player.embed.setVolume(toggle ? 0 : player.config.volume);
|
||||
utils.dispatchEvent.call(player, player.media, 'volumechange');
|
||||
|
||||
player.embed.setVolume(toggle ? 0 : player.config.volume).then(() => {
|
||||
muted = toggle;
|
||||
utils.dispatchEvent.call(player, player.media, 'volumechange');
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@ -161,8 +170,11 @@ const vimeo = {
|
||||
return loop;
|
||||
},
|
||||
set(input) {
|
||||
loop = utils.is.boolean(input) ? input : player.config.loop.active;
|
||||
player.embed.setLoop(loop);
|
||||
const toggle = utils.is.boolean(input) ? input : player.config.loop.active;
|
||||
|
||||
player.embed.setLoop(toggle).then(() => {
|
||||
loop = toggle;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@ -269,6 +281,11 @@ const vimeo = {
|
||||
utils.dispatchEvent.call(player, player.media, 'ended');
|
||||
});
|
||||
|
||||
player.embed.on('error', detail => {
|
||||
player.media.error = detail;
|
||||
utils.dispatchEvent.call(player, player.media, 'error');
|
||||
});
|
||||
|
||||
// Rebuild UI
|
||||
window.setTimeout(() => ui.build.call(player), 0);
|
||||
},
|
||||
|
@ -81,10 +81,47 @@ const youtube = {
|
||||
},
|
||||
events: {
|
||||
onError(event) {
|
||||
utils.dispatchEvent.call(player, player.media, 'error', true, {
|
||||
// If we've already fired an error, don't do it again
|
||||
// YouTube fires onError twice
|
||||
if (utils.is.object(player.media.error)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const detail = {
|
||||
code: event.data,
|
||||
embed: event.target,
|
||||
});
|
||||
};
|
||||
|
||||
// Messages copied from https://developers.google.com/youtube/iframe_api_reference#onError
|
||||
switch (event.data) {
|
||||
case 2:
|
||||
detail.message =
|
||||
'The request contains an invalid parameter value. For example, this error occurs if you specify a video ID that does not have 11 characters, or if the video ID contains invalid characters, such as exclamation points or asterisks.';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
detail.message =
|
||||
'The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.';
|
||||
break;
|
||||
|
||||
case 100:
|
||||
detail.message =
|
||||
'The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private.';
|
||||
break;
|
||||
|
||||
case 101:
|
||||
case 150:
|
||||
detail.message =
|
||||
'The owner of the requested video does not allow it to be played in embedded players.';
|
||||
break;
|
||||
|
||||
default:
|
||||
detail.message = 'An unknown error occured';
|
||||
break;
|
||||
}
|
||||
|
||||
player.media.error = detail;
|
||||
|
||||
utils.dispatchEvent.call(player, player.media, 'error');
|
||||
},
|
||||
onPlaybackQualityChange(event) {
|
||||
// Get the instance
|
||||
|
@ -525,7 +525,7 @@ const utils = {
|
||||
},
|
||||
|
||||
// Trigger event
|
||||
dispatchEvent(element, type, bubbles, properties) {
|
||||
dispatchEvent(element, type, bubbles, detail) {
|
||||
// Bail if no element
|
||||
if (!element || !type) {
|
||||
return;
|
||||
@ -534,7 +534,7 @@ const utils = {
|
||||
// Create and dispatch the event
|
||||
const event = new CustomEvent(type, {
|
||||
bubbles: utils.is.boolean(bubbles) ? bubbles : false,
|
||||
detail: Object.assign({}, properties, {
|
||||
detail: Object.assign({}, detail, {
|
||||
plyr: this instanceof Plyr ? this : null,
|
||||
}),
|
||||
});
|
||||
|
@ -53,7 +53,7 @@
|
||||
.plyr__play-large {
|
||||
display: none;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
z-index: 3;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
|
@ -6,7 +6,8 @@
|
||||
.plyr__video-embed {
|
||||
// Default to 16:9 ratio but this is set by JavaScript based on config
|
||||
@padding: ((100 / 16) * 9);
|
||||
@offset: unit((300 - @padding) / 6, ~'%');
|
||||
@height: 200;
|
||||
@offset: unit((@height - @padding) / (@height / 50), ~'%');
|
||||
|
||||
padding-bottom: unit(@padding, ~'%');
|
||||
height: 0;
|
||||
@ -24,7 +25,7 @@
|
||||
// Vimeo hack
|
||||
> div {
|
||||
position: relative;
|
||||
padding-bottom: 300%;
|
||||
padding-bottom: unit(@height, ~'%');
|
||||
transform: translateY(-@offset);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user