Ratio improvements
This commit is contained in:
parent
f0d3e8c3b9
commit
7a4a7dece8
@ -318,7 +318,7 @@ class Listeners {
|
|||||||
|
|
||||||
const target = player.elements.wrapper.firstChild;
|
const target = player.elements.wrapper.firstChild;
|
||||||
const [, y] = ratio;
|
const [, y] = ratio;
|
||||||
const [videoX, videoY] = getAspectRatio.call(this);
|
const [videoX, videoY] = getAspectRatio.call(player);
|
||||||
|
|
||||||
target.style.maxWidth = toggle ? `${(y / videoY) * videoX}px` : null;
|
target.style.maxWidth = toggle ? `${(y / videoY) * videoX}px` : null;
|
||||||
target.style.margin = toggle ? '0 auto' : null;
|
target.style.margin = toggle ? '0 auto' : null;
|
||||||
@ -356,7 +356,7 @@ class Listeners {
|
|||||||
const { padding, ratio } = setPlayerSize(isEnter);
|
const { padding, ratio } = setPlayerSize(isEnter);
|
||||||
|
|
||||||
// Set Vimeo gutter
|
// Set Vimeo gutter
|
||||||
setGutter.call(player, ratio, padding, isEnter);
|
setGutter(ratio, padding, isEnter);
|
||||||
|
|
||||||
// If not using native fullscreen, we need to check for resizes of viewport
|
// If not using native fullscreen, we need to check for resizes of viewport
|
||||||
if (!usingNative) {
|
if (!usingNative) {
|
||||||
|
@ -281,7 +281,7 @@ const vimeo = {
|
|||||||
// Set aspect ratio based on video size
|
// Set aspect ratio based on video size
|
||||||
Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then(dimensions => {
|
Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then(dimensions => {
|
||||||
const [width, height] = dimensions;
|
const [width, height] = dimensions;
|
||||||
player.embed.ratio = `${width}:${height}`;
|
player.embed.ratio = [width, height];
|
||||||
setAspectRatio.call(this);
|
setAspectRatio.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,9 +52,6 @@ const youtube = {
|
|||||||
// Add embed class for responsive
|
// Add embed class for responsive
|
||||||
toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
|
toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
|
||||||
|
|
||||||
// Set aspect ratio
|
|
||||||
setAspectRatio.call(this);
|
|
||||||
|
|
||||||
// Setup API
|
// Setup API
|
||||||
if (is.object(window.YT) && is.function(window.YT.Player)) {
|
if (is.object(window.YT) && is.function(window.YT.Player)) {
|
||||||
youtube.ready.call(this);
|
youtube.ready.call(this);
|
||||||
@ -84,33 +81,27 @@ const youtube = {
|
|||||||
|
|
||||||
// Get the media title
|
// Get the media title
|
||||||
getTitle(videoId) {
|
getTitle(videoId) {
|
||||||
// Try via undocumented API method first
|
const url = format(this.config.urls.youtube.api, videoId);
|
||||||
// This method disappears now and then though...
|
|
||||||
// https://github.com/sampotts/plyr/issues/709
|
|
||||||
if (is.function(this.embed.getVideoData)) {
|
|
||||||
const { title } = this.embed.getVideoData();
|
|
||||||
|
|
||||||
if (is.empty(title)) {
|
fetch(url)
|
||||||
this.config.title = title;
|
.then(data => {
|
||||||
ui.setTitle.call(this);
|
if (is.object(data)) {
|
||||||
return;
|
const { title, height, width } = data;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Or via Google API
|
// Set title
|
||||||
const key = this.config.keys.google;
|
this.config.title = title;
|
||||||
if (is.string(key) && !is.empty(key)) {
|
ui.setTitle.call(this);
|
||||||
const url = format(this.config.urls.youtube.api, videoId, key);
|
|
||||||
|
|
||||||
fetch(url)
|
// Set aspect ratio
|
||||||
.then(result => {
|
this.embed.ratio = [width, height];
|
||||||
if (is.object(result)) {
|
}
|
||||||
this.config.title = result.items[0].snippet.title;
|
|
||||||
ui.setTitle.call(this);
|
setAspectRatio.call(this);
|
||||||
}
|
})
|
||||||
})
|
.catch(() => {
|
||||||
.catch(() => {});
|
// Set aspect ratio
|
||||||
}
|
setAspectRatio.call(this);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// API ready
|
// API ready
|
||||||
|
@ -894,6 +894,10 @@ class Plyr {
|
|||||||
* Get the current aspect ratio in use
|
* Get the current aspect ratio in use
|
||||||
*/
|
*/
|
||||||
get ratio() {
|
get ratio() {
|
||||||
|
if (!this.isVideo) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const ratio = reduceAspectRatio(getAspectRatio.call(this));
|
const ratio = reduceAspectRatio(getAspectRatio.call(this));
|
||||||
|
|
||||||
return is.array(ratio) ? ratio.join(':') : ratio;
|
return is.array(ratio) ? ratio.join(':') : ratio;
|
||||||
|
@ -44,8 +44,14 @@ export function getAspectRatio(input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get from embed
|
// Get from embed
|
||||||
if (ratio === null && !is.empty(this.embed) && is.string(this.embed.ratio)) {
|
if (ratio === null && !is.empty(this.embed) && is.array(this.embed.ratio)) {
|
||||||
ratio = parse(this.embed.ratio);
|
({ ratio } = this.embed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get from HTML5 video
|
||||||
|
if (ratio === null && this.isHTML5) {
|
||||||
|
const { videoWidth, videoHeight } = this.media;
|
||||||
|
ratio = reduceAspectRatio([videoWidth, videoHeight]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ratio;
|
return ratio;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user