Home > Software engineering >  How to play rtmp video in the webpage?
How to play rtmp video in the webpage?

Time:08-03

I want to stream the video from rtmp://1.32.196.6/live/BTBV05_2 to my webpage in laravel. I try to use hls.js but not working. If hls.js not be used with this kind of videos, please provide the other solutions. My code like below

<video id="video" autoplay="true" muted="muted"></video>
<script>
    if (Hls.isSupported()) {
      var video = document.getElementById('video');
      var hls = new Hls();
      // bind them together
      hls.attachMedia(video);
      hls.on(Hls.Events.MEDIA_ATTACHED, function () {
        console.log('video and hls.js are now bound together !');
        hls.loadSource('rtmp://1.32.196.6/live/BTBV05_2');
        hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
          video.play();
          console.log(
            'manifest loaded, found '   data.levels.length   ' quality level'
          );
        });
      });
    }
    
  </script>

CodePudding user response:

RTMP is usually not supported in browsers of in most Javascript video players now.

If you can convert your video stream to use HLS or DASH that will be supported by the vast majority of Javascript video players across browsers - e.g, by video.js (https://github.com/videojs/video.js) ShakaPlayer (https://shaka-player-demo.appspot.com/dem).

  • Related