VideoJS像YouTube一样调整视频大小

huangapple go评论63阅读模式
英文:

VideoJS scale video like youtube

问题

我正在尝试使用VideoJS来调整我的视频,以使其始终适应窗口的缩放,视频的尺寸是1280x720,我正在寻找一种解决方案,就像在YouTube剧院模式中一样,视频将居中并尽可能大,但会在两侧添加黑边。

当前代码:

<html>
<head>
    <title>Test Video</title>
</head>
<body>
    <link rel="stylesheet" href="video-js.css" type="text/css">
    <div class="container">
        <div class="VideoJS">
            <div id="Video">
                <video id="vid1" class="video-js vjs-fluid" controls preload="auto" playsinline webkit-playsinline
                    style="max-width: 100%;">
                    <source src="testvideo.mp4">
                </video>
                <script src="video.min.js"></script>
                <script>
                    var player = videojs('vid1', {})
                </script>
            </div>
        </div>
    </div>
</body>
</html>

编辑:

以下代码将呈现出我想要的播放器行为,但它占据了整个页面,因此我需要它包含在一个div中,但仍然可以像这样缩放:

<html>
<head>
    <title>Test Video</title>
</head>
<body>
    <script src="video.min.js"></script>
    <link rel="stylesheet" href="video-js.css" type="text/css">
    <video id="my_video_1" style="width: 100%; height: 100%; top: 0px; position: absolute; background-color: black;"
        class="video-js" controls>
        <source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
    </video>
</body>
</html>
英文:

I'm trying with VideoJS to scale my video so it always fits when window is scaling, the video is 1280x720 and looking for a solution like when you in youtbe theater mode, the video will be centered and as large as possbile but add black bars to side.

current code:

    &lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Test Video&lt;/title&gt;


&lt;body&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;video-js.css&quot; type=&quot;text/css&quot;&gt;


    &lt;div class=&quot;container&quot;&gt;
        &lt;div class=&quot;VideoJS&quot;&gt;

            &lt;div id=&quot;Video&quot;&gt;
                &lt;video id=&quot;vid1&quot; class=&quot;video-js vjs-fluid&quot; controls preload=&quot;auto&quot; playsinline webkit-playsinline
                    style=&quot;max-width: 100%&quot;&gt;
                    &lt;source src=&quot;testvideo.mp4&quot;&gt;
                &lt;/video&gt;
                &lt;script src=&quot;video.min.js&quot;&gt;&lt;/script&gt;

                &lt;script&gt;
                    var player = videojs(&#39;vid1&#39;, {})
                &lt;/script&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

Edit:

This code below will present the player as I want it to behave but it takes up the whole page, so I need it to contain in a div but still scale as this code:

&lt;html&gt;

&lt;head&gt;
    &lt;title&gt;Test Video&lt;/title&gt;

&lt;body&gt;
    &lt;script src=&quot;video.min.js&quot;&gt;&lt;/script&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;video-js.css&quot; type=&quot;text/css&quot;&gt;
    &lt;video id=&quot;my_video_1&quot; style=&quot;width: 100%;height: 100%;top: 0px;position: absolute;background-color: black;&quot;
        class=&quot;video-js&quot; controls&gt;
        &lt;source src=&quot;http://vjs.zencdn.net/v/oceans.mp4&quot; type=&#39;video/mp4&#39;&gt;
    &lt;/video&gt;
 
&lt;/body&gt;

&lt;/html&gt;

答案1

得分: 0

以下是翻译好的内容:

"Ok I think I've solved it, this is the css

.container {
position: relative;
width: 100%;
height: 56.25vw;
max-height: calc(100vh - 250px);
min-height: 480px;
background: #000;
}

The max-height is subtraced the amount of space above the container div"

英文:

Ok I think I've solved it, this is the css

.container {
  position: relative;
    width: 100%;
    height: 56.25vw;
    max-height: calc(100vh - 250px);
    min-height: 480px;
    background: #000;
}

The max-height is subtraced the amount of space above the container div

huangapple
  • 本文由 发表于 2023年5月30日 05:46:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360481.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定