简体   繁体   English

Video-js 标签自动播放 HLS 直播流

[英]Video-js tag autoplay HLS Live stream

I am live streaming via videojs.我正在通过 videojs 直播。 The stream works but I am unable to get it to autoplay.流有效,但我无法让它自动播放。 Instead I need to click the play button each time I go on the page.相反,我每次进入页面时都需要单击播放按钮。

<video-js id="my_video" autoplay controls preload="auto" width="762" height="428" poster="images/poster2.jpg">
          <source src="http://xx.xxx.xxx.xx:1935/live/xxxxx/playlist.m3u8" type="application/x-mpegURL">
          </video-js>

  <script src="https://unpkg.com/video.js/dist/video.js"></script>
  <script src="https://unpkg.com/@videojs/http-streaming/dist/videojs-http-streaming.js"></script>

  <script>
    var player = videojs('my_video');
    video.autoplay = true
  </script>

Many browsers won't allow autoplay now unless the video is muted.许多浏览器现在不允许自动播放,除非视频被静音。 You can add the muted attribute.您可以添加muted属性。

You can also use the any option for autoplay, in which case the video will be autoplayed with sound if possible, if not then autoplayed muted if that is possible.您还可以使用any选项进行自动播放,在这种情况下,如果可能,视频将自动播放声音,如果没有,则自动播放静音(如果可能)。 Remove the autoplay attribute and use a setup option instead:删除autoplay属性并改用设置选项:

var player = videojs('my_video', {autoplay: 'any'});
var options, player;

options = {
    controls: true,
    autoplay:'any',
    techOrder: [ 'chromecast', 'html5' ],
    plugins: {
        chromecast: {}
    }
};

player = videojs(document.getElementById('vjs'), options, function() {
        player.chromecast();
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM