2015-12-08 84 views
1

我正在尝试使用video.js在所有平台上保持一致的视频皮肤。下面的代码适用于所有东西(chrome,firefox,即android),但是ios上的safari(尚未测试safari的桌面版本)。试图播放视频时,ios会踢到它的默认视频播放器(quicktime?)。这是一个问题,因为我正在寻找从皮肤中删除视频控件,以便用户必须观看视频。有没有办法使用video.js或其他网络插件,以便能够在所有平台上拥有一致的视频播放器用户界面,或者这对ios不可行?使用video.js在ios上播放视频内嵌视频?

<html> 

<head> 
    <!--#include virtual="/assets/inc/headcontent.htm" --> 


    <link href="http://vjs.zencdn.net/5.3.0/video-js.css" rel="stylesheet"> 

    <!-- If you'd like to support IE8 --> 
    <script src="http://vjs.zencdn.net/ie8/1.1.0/videojs-ie8.min.js"></script> 


</head> 
<body> 

    <div class="row"> 

     <div class="col-xs-12 col-md-10 col-lg-8"> 

      <div class=""> 
       <video id="the_video" class="video-js" controls preload="auto"> 
        <source src="videos/english.mp4" type='video/mp4'> 
        <p class="vjs-no-js"> 
         To view this video please enable JavaScript, and consider upgrading to a web browser that 
         <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a> 
        </p> 
       </video> 
      </div> 

     </div> 

    </div> 


    <!--#include virtual="/assets/inc/footcontent.htm" --> 


    <script src="http://vjs.zencdn.net/5.3.0/video.js"></script> 


    <script> 

    var player = videojs("the_video", {}, function(){ 
     // Player (this) is initialized and ready. 
    }).ready(function(){ 

     console.log(this.options()); //log all of the default videojs options 

     // Store the video object 
     var myPlayer = this, id = myPlayer.id(); 
     // Make up an aspect ratio 
     var aspectRatio = 264/640; 

     function resizeVideoJS(){ 
     var width = document.getElementById(id).parentElement.offsetWidth; 
     myPlayer.width(width).height(width * aspectRatio); 

     } 

     // Initialize resizeVideoJS() 
     resizeVideoJS(); 
     // Then on resize call resizeVideoJS() 
     window.onresize = resizeVideoJS; 
    }); 


    </script> 

</body> 
</html> 

回答

1

在iOS 9和10中,您现在可以将playsinline属性添加到视频标签以使其以内联方式播放。 https://webkit.org/blog/6784/new-video-policies-for-ios/我刚刚测试过,它可以与video.js一起使用

<video class="video-js" poster="#" playsinline autoplay loop> 
    <source src="#" type="video/mp4"> 
</video> 
0

这很烦人,但iOS仍然不允许在iPhone上进行视频元素的内联播放。有些人试图在画布元素中播放视频,而不是像this question的答案中提到的那样。