diff options
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r-- | src/js/plyr.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index c06df984..1dd3ecb9 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -26,6 +26,7 @@ import { off, on, once, triggerEvent, unbindListeners } from './utils/events'; import is from './utils/is'; import loadSprite from './utils/loadSprite'; import { cloneDeep, extend } from './utils/objects'; +import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateRatio } from './utils/style'; import { parseUrl } from './utils/urls'; // Private properties @@ -847,6 +848,34 @@ class Plyr { } /** + * Get the current aspect ratio in use + */ + get ratio() { + const ratio = reduceAspectRatio(getAspectRatio.call(this)); + + return is.array(ratio) ? ratio.join(':') : ratio; + } + + /** + * Set video aspect ratio + */ + set ratio(input) { + if (!this.isVideo) { + this.debug.warn('Aspect ratio can only be set for video'); + return; + } + + if (!is.string(input) || !validateRatio(input)) { + this.debug.error(`Invalid aspect ratio specified (${input})`); + return; + } + + this.config.ratio = input; + + setAspectRatio.call(this); + } + + /** * Set the autoplay state * @param {Boolean} input - Whether to autoplay or not */ |