繁体   English   中英

我想在我的应用程序上进行 m3u8 直播。 那么任何人都可以帮助我如何做到这一点? 我尝试使用 exoplayer 但我失败了

[英]i want to do m3u8 live streaming on my app. So can anyone help me how can i do this ? i tried with exoplayer but i failed

我想用 exoplayer 开发一个实时流媒体应用程序,我尝试使用 exo player 但我没有做到这一点。 谁能帮我做到这一点,,?

是的,我可以帮忙,有一个名为 HLS.js 的工具。 您可以使用此工具嵌入任何带有 m3u8 扩展名的 stream,这是链接: HLS.js

如果您的 stream 不安全,您需要使用http网站,如果不是,您可以使用https 我会给你一个示例代码:

<script src="https://cdn.jsdelivr.net/npm/hls.js@1"></script>
<!-- Or if you want the latest version from the main branch -->
<!-- <script src="https://cdn.jsdelivr.net/npm/hls.js@canary"></script> -->
<video id="video"></video>
<script>
  var video = document.getElementById('video');
  var videoSrc = 'YOUR-STREAM-SOURCE';
  if (Hls.isSupported()) {
    var hls = new Hls();
    hls.loadSource(videoSrc);
    hls.attachMedia(video);
  }
  // HLS.js is not supported on platforms that do not have Media Source
  // Extensions (MSE) enabled.
  //
  // When the browser has built-in HLS support (check using `canPlayType`),
  // we can provide an HLS manifest (i.e. .m3u8 URL) directly to the video
  // element through the `src` property. This is using the built-in support
  // of the plain video element, without using HLS.js.
  //
  // Note: it would be more normal to wait on the 'canplay' event below however
  // on Safari (where you are most likely to find built-in HLS support) the
  // video.src URL must be on the user-driven white-list before a 'canplay'
  // event will be emitted; the last video event that can be reliably
  // listened-for when the URL is not on the white-list is 'loadedmetadata'.
  else if (video.canPlayType('application/vnd.apple.mpegurl')) {
    video.src = videoSrc;
  }
</script>

如果此扩展程序可以在任何设备上播放,则视频将与您的 stream 具有相同的源。

希望我有帮助!

暂无
暂无

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

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