简体   繁体   English

TS文件未播放hls.js

[英]TS file not playing hls.js

Need some help. 需要一些帮助。 Video loads in browser but never starts playing. 视频已加载到浏览器中,但从未开始播放。 I'm using hls.js to stream m3u8 playlist to the browser. 我正在使用hls.js将m3u8播放列表流式传输到浏览器。 And I use FFmpeg to create ts and m3u8 files. 我使用FFmpeg创建ts和m3u8文件。

For FFmpeg : 对于FFmpeg:

./ffmpeg -rtsp_transport tcp -i rtsp://user:password@ipaddress/axis-media/media.amp -vcodec copy -hls_time 4 -hls_list_size 4 -hls_wrap 4 -start_number 1 -y test.m3u8

HTML Code: HTML代码:

<!DOCTYPE html>
<html>
  <head>
     <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
  </head>

  <body>
     <video id="video" height="800px" width="1200px"></video>
  <body>

  <script>
     var video = document.getElementById('video');
     if(Hls.isSupported()){
        var hls = new Hls();
        hls.loadSource('/images/live/test.m3u8');
        hls.attachMedia(video);
        hls.on(Hls.Events.MANIFEST_PARSED,function() {
              video.play();
         });
      }
      else if (video.canPlayType('application/vnd.apple.mpegurl')){
         video.src = '/images/live/test.m3u8';
         video.addEventListener('loadedmetadata',function() {
              video.play();
         });
      }
   </script>
</html>

只需将ffmpeg命令行更改为:ffmpeg -rtsp_transport tcp -i rtsp:// user:password@ip_address/axis-media/media.amp -y -s 854x480 -codec:v libx264 -b:v 800000 -hls_time 4- hls_list_size 4 -hls_wrap 4 start_number 0 test.m3u8

There are two issues with your code. 您的代码有两个问题。

  1. the play need the blowser allow the audio auto display 该剧需要鼓风机允许音频自动显示

    NotAllowedError: The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. NotAllowedError:在当前上下文中,用户代理或平台不允许使用play方法,这可能是因为用户拒绝了权限。

  2. the hls.js cannot access it's map file hls.js无法访问其地图文件

    request failed with status 404 请求失败,状态为404
    URL:hls.min.js.map 网址:hls.min.js.map

Just change it to a workable cdn 只需将其更改为可行的CDN

 <!DOCTYPE html> <html> <head> <script src="https://cdn.jsdelivr.net/npm/hls.js"></script> </head> <body> <video id="video" height="800px" width="1200px"></video> <body> <script> var video = document.getElementById('video'); if(Hls.isSupported()){ var hls = new Hls(); hls.loadSource('http://vfile1.grtn.cn/2018/1542/0254/3368/154202543368.ssm/154202543368.m3u8'); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED,function() { video.play(); }); } else if (video.canPlayType('application/vnd.apple.mpegurl')){ video.src = 'http://vfile1.grtn.cn/2018/1542/0254/3368/154202543368.ssm/154202543368.m3u8'; video.addEventListener('loadedmetadata',function() { video.play(); }); } </script> </html> 

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

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