Merge pull request #678 from StudyTube/use-url-as-input-for-vimeo-player

Add URL as a possible input option to Vimeo player
This commit is contained in:
Sam Potts 2017-11-04 21:24:55 +11:00 committed by GitHub
commit 7ac5b0e18b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -662,10 +662,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
@ -1616,6 +1616,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
@ -1625,7 +1626,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:
@ -1690,11 +1698,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
@ -1898,17 +1906,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() {