简体   繁体   中英

Video-js tag autoplay HLS Live stream

I am live streaming via 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.

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. Remove the autoplay attribute and use a setup option instead:

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();
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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