簡體   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