【问题标题】:How to make videos same shape and height如何使视频具有相同的形状和高度
【发布时间】:2019-02-26 10:33:22
【问题描述】:

我已将两个视频上传到数据库并显示在我的网站上。我试图使它们具有相同的形状和高度。宽度很好,但其中一个形状像正方形,高度较长,而另一个是矩形,高度较短,我知道这是因为视频拍摄的方式,一个是垂直拍摄的,另一个是水平拍摄的。如何使它们具有相同的形状和高度。你能帮帮我吗?

     I tried this 

    <video class="video1" id="cb" preload="auto" video="src="{{$proo->video}}#t=1""   style=" height:80%; max-height:20em; width:100%; max-width:20em; object-fit: cover; 
 float:left; clear:both; 
     padding-left:2%;  margin-top:0px;     cursor:pointer; "><source="video1.jpg" playsinline alt="Video Unavailable"   id="" ></source>
  </video>

      this the javascript part to  handle the onclick,onmouseleave


  $(document).on('mouseover touchstart', 'video', function() { 
        $(this).get(0).play();
        this.muted=true;
    }); 



    //pause video on mouse leave
    $(document).on('mouseleave', 'video', function() { 

        this.currentTime = 1;
        $(this).get(0).pause(); 

    });

    $(document).on('click touchstart', 'video', function() { 
        $(this).get(0).play();
        this.muted=false;
        this.currentTime = 0;

    }); 

【问题讨论】:

    标签: php html css laravel html5-video


    【解决方案1】:

    当我需要在 iframe 中输出 YouTube 视频时,我想出了一个小东西,它的响应速度非常快,这意味着它可以根据当前屏幕尺寸调整其高度和宽度。

    <style>
           #mediaPlayer{
            position: relative;
            height: auto;
            padding-bottom: 56.25%;
            padding-top: 1.875em; 
            overflow: hidden;
            border: 0.1875em double #185875; 
            background-image:url('../video_loading.gif'); 
            background-repeat: no-repeat;
            background-size: cover;
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-position: center;
            background-attachment: fixed;
           }
    
        #mediaPlayer iframe{
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            max-width: 100%;
            max-height: 100%;   
        }
    </style>
    
    /*use the div to specify the exact height and width you want*/ 
    
    <div style="height: 50%; width:50%;">
     <center>
      <div id="mediaPlayer">
        <iframe id="play_now" width="100%" height="100%" src="source here" value="value here" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
      </div>
     </center>
    </div>
    

    video_loading.gif 背景对于网络速度较慢的用户来说通常是一个好主意,可以在加载 iframe 内容时在后台添加一些东西

    但您必须找到自己独特的 gif 文件/图像并将其位置设置在 background-image:url('../file-location-here.gif');

    【讨论】:

    • 是 iframe 的唯一方法吗?
    • 没有其他方法,但 iframe 通常是调整响应式视频大小的方法,您可以将上述代码中的 iframe 替换为 &lt;video&gt; 标签,但请务必排除您的&lt;style&gt; 标记否则它将覆盖当前样式
    • 好的,我正在尝试 iframe,但我需要一个一个播放视频,它也会自动开始播放,这是我不想要的。我只需要在点击时播放,我的浏览器一直在询问如果我想把视频下载到我的电脑上,但我不知道为什么
    • 您要求播放、暂停、下一个、上一个按钮是一种媒体播放器控件吗?因为它们是插件,堆栈上的很多这样的答案只是搜索它:)
    • 不是这样,但更像是在鼠标离开停止时点击播放视频。这就是我现在在我的代码中所拥有的,但它是为视频做的。我编辑了我的代码,所以你可以看到我在说什么
    猜你喜欢
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多