Video.js: how to set the video width and height to adapt to the mobile device screen

Created on 17 Jul 2016  路  2Comments  路  Source: videojs/video.js

Most helpful comment

When creating your player, you can pass the fluid: true option:

var myPlayer = videojs('my-video', {fluid: true});

Or you can set it after initialization at some point:

myPlayer.fluid(true);

All 2 comments

My simple solution

    $(document).ready(function($) {
        videojs('video', {height: 'auto', width: 'auto'}).ready(function() {

            var player = this,
                aspectRatio = 9/16;

            function resizeVideoJS() {
                var width = document.getElementById(player.id()).parentElement.clientWidth;
                player.width(width).height(width * aspectRatio);
            }

            resizeVideoJS();
            window.onresize = resizeVideoJS;
        });
    });

When creating your player, you can pass the fluid: true option:

var myPlayer = videojs('my-video', {fluid: true});

Or you can set it after initialization at some point:

myPlayer.fluid(true);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

aagiulian picture aagiulian  路  3Comments

zhulduz picture zhulduz  路  3Comments

dingyaguang117 picture dingyaguang117  路  4Comments

kocoten1992 picture kocoten1992  路  4Comments

victorpfm picture victorpfm  路  4Comments