Add URL as a possible input option to Vimeo player

This is reasonable to processing correctly private Vimeo links, like https://vimeo.com/25345658/fe46e209ac - that contain not only vimeo id, but also private key
This commit is contained in:
Yuriy Kuzin 2017-10-06 14:41:57 +03:00
parent b3759e966d
commit 1b3a6b340d

View File

@ -654,10 +654,10 @@
return url.match(regex) ? RegExp.$2 : url; return url.match(regex) ? RegExp.$2 : url;
} }
// Parse Vimeo ID from url // Is this a Vimeo url link?
function _parseVimeoId(url) { function _isVimeoUrl(url) {
var regex = /^.*(vimeo.com\/|video\/)(\d+).*/; var regex = /^.*(vimeo.com\/|video\/)(\d+).*/;
return url.match(regex) ? RegExp.$2 : url; return url.match(regex);
} }
// Fullscreen API // Fullscreen API
@ -1608,6 +1608,7 @@
function _setupEmbed() { function _setupEmbed() {
var container = document.createElement("div"), var container = document.createElement("div"),
mediaId, mediaId,
mediaUrl,
id = plyr.type + "-" + Math.floor(Math.random() * 10000); id = plyr.type + "-" + Math.floor(Math.random() * 10000);
// Parse IDs from URLs if supplied // Parse IDs from URLs if supplied
@ -1617,7 +1618,14 @@
break; break;
case "vimeo": case "vimeo":
mediaId = _parseVimeoId(plyr.embedId); if (_isVimeoUrl(plyr.embedId)) {
mediaId = null;
mediaUrl = plyr.embedId;
} else {
mediaId = parseInt(plyr.embedId);
mediaUrl = null;
}
break; break;
default: default:
@ -1682,11 +1690,11 @@
var vimeoTimer = window.setInterval(function() { var vimeoTimer = window.setInterval(function() {
if (_is.object(window.Vimeo)) { if (_is.object(window.Vimeo)) {
window.clearInterval(vimeoTimer); window.clearInterval(vimeoTimer);
_vimeoReady(mediaId, container); _vimeoReady(mediaId, mediaUrl, container);
} }
}, 50); }, 50);
} else { } else {
_vimeoReady(mediaId, container); _vimeoReady(mediaId, mediaUrl, container);
} }
} else if (plyr.type === "soundcloud") { } else if (plyr.type === "soundcloud") {
// TODO: Currently unsupported and undocumented // TODO: Currently unsupported and undocumented
@ -1890,17 +1898,27 @@
} }
// Vimeo ready // Vimeo ready
function _vimeoReady(mediaId, container) { function _vimeoReady(mediaId, mediaUrl, container) {
// Setup instance // Setup instance
// https://github.com/vimeo/player.js // https://github.com/vimeo/player.js
plyr.embed = new window.Vimeo.Player(container, {
id: parseInt(mediaId), var vimeoOptions = {
loop: config.loop, loop: config.loop,
autoplay: config.autoplay, autoplay: config.autoplay,
byline: false, byline: false,
portrait: false, portrait: false,
title: false title: false
}); };
if (mediaId) {
vimeoOptions.id = mediaId;
}
if (mediaUrl) {
vimeoOptions.url = mediaUrl;
}
plyr.embed = new window.Vimeo.Player(container, vimeoOptions);
// Create a faux HTML5 API using the Vimeo API // Create a faux HTML5 API using the Vimeo API
plyr.media.play = function() { plyr.media.play = function() {