videojs--跨瀏覽器的HTML視頻播放器(可自定義樣式)

官網css

寫在前面,爲何選擇這個播放器,由於有文檔,支持添加插件,很方便自定義樣式,
比較活躍,github有各類bug解決方案等
不過沒想到有那麼多坑

最簡單的靜態頁面使用方法html

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

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

<body>
  <video id="my-video" class="video-js" controls preload="auto" width="640" height="264"
  poster="MY_VIDEO_POSTER.jpg" data-setup="{}">
    <source src="MY_VIDEO.mp4" type='video/mp4'>
    <source src="MY_VIDEO.webm" type='video/webm'>
    <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>

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

動態插入HTML時初始化方法html5

videojs("example_video_id", {}, function(){
  // Player (this) is initialized and ready.
});

或者

videojs(document.getElementById('example_video_id'), {}, function() {
  // This is functionally the same as the previous example.
});

或者

videojs(document.getElementsByClassName('awesome_video_class')[0], {}, function() {
  // You can grab an element by class if you'd like, just make sure
  // if it's an array that you pick one (here we chose the first).
});

更多詳細使用方法請查看官方文檔git

常見問題彙總github

1,pc端正常,IOS上面不起做用web

data-setup='{"customControlsOnMobile": true}'//版本4

data-setup='{"nativeControlsForTouch": false}' //版本5

或者寫在
videojs(document.getElementById('example_video_id'), {"nativeControlsForTouch": false}, function() {
  // This is functionally the same as the previous example.
});

2,其它錯誤app

先調用官方的視頻作測試,http://vjs.zencdn.net/v/oceans.mp4,

若是這個正常,其它的格式異常,請參考:

[異常1][2]  http://stackoverflow.com/questions/16697473/videojs-4-native-controls-now-default-on-mobile

[異常2][3] http://stackoverflow.com/questions/26182101/videojs-hls-not-working

3,只是在Iphone上不起做用(官網示例 5.8)參考:github issueide

if (browser.TOUCH_ENABLED && options.nativeControlsForTouch === true || browser.IS_IPHONE || browser.IS_NATIVE_ANDROID) {
                this.setControls(true);
            }
            
 //替換爲
if ((browser.TOUCH_ENABLED || browser.IS_IPHONE || browser.IS_IPHONE || browser.IS_NATIVE_ANDROID) && options.nativeControlsForTouch === true){
                this.setControls(true);
            }

4,默認不全屏播放post

前臺:<video webkit-playsinline ></video>

IOS 參考:

https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#//apple_ref/doc/uid/TP40008058-SW30
相關文章
相關標籤/搜索