VideoJs with live stream

2019-04-02 07:22发布

问题:

I am trying to get videoJs to work with a live stream I have a this link which contains an rtmp live stream.
http://www.iptv-player.com/index.php?fdb=1&title=%20+JIMTV%20%20&stream=rtmp%3A%2F%2Frtmp.jim.stream.vmmacdn.be%2Fvmma-jim-rtmplive-live%2Fjim
and the player itself has a link which is:
rtmp://rtmp.jim.stream.vmmacdn.be/vmma-jim-rtmplive-live/jim
I am currently just trying to get the live stream to play on the videoJs player I have already got the local video to work just cant fathom out how to get the live stream to work.
Here is my html for what i have so far

<!DOCTYPE html>
<html>
<head>
  <title>Video.js | HTML5 Video Player</title>

  <!-- Chang URLs to wherever Video.js files will be hosted -->
  <link href="video-js.css" rel="stylesheet" type="text/css">
  <!-- video.js must be in the <head> for older IEs to work. -->
  <script src="video.js"></script>

  <!-- Unless using the CDN hosted version, update the URL to the Flash SWF -->
  <script>
    videojs.options.flash.swf = "video-js.swf";
  </script>


</head>
<body>

  <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="264"
      poster="http://www.pageresource.com/wallpapers/wallpaper/bleach-ichigo-mugetsu-here-size-original_215405.jpg"
      data-setup="{}">
    <
    <source src="http://www.iptv-player.com/index.php?fdb=1&title=%20+JIMTV%20%20&stream=rtmp%3A%2F%2Frtmp.jim.stream.vmmacdn.be%2Fvmma-jim-rtmplive-live%2Fjim" type='video/mp4' />
    <!--<track kind="captions" src="demo.captions.vtt" srclang="en" label="English"></track>--><!-- Tracks need an ending tag thanks to IE9 -->
    <!--<track kind="subtitles" src="demo.captions.vtt" srclang="en" label="English"></track>--><!-- Tracks need an ending tag thanks to IE9 -->
  </video>

</body>
</html>

回答1:

So I Looked more into this and found out that it was because I was trying to do this locally. I put my code onto the JsFiddle and it worked. So all I can logically say is that the files must be on a web server for the player to work.
This worked for me not sure if it can be done locally but the only way I could get it to work was on a web server



回答2:

Try changing your source type to rtmp/flv instead of video/mp4



回答3:

The type needs to be

type="rtmp/mp4"

if you want live streaming to work, and if you want device switching to work, you need another source with

type="application/x-mpegurl"