[英]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
I want to develop a live streaming app with exoplayer, I tried with exo player but i failed to do this.我想用 exoplayer 开发一个实时流媒体应用程序,我尝试使用 exo player 但我没有做到这一点。 can anyone help me to do this,, ?
谁能帮我做到这一点,,?
Yes, I can help, there is a tool that is called HLS.js.是的,我可以帮忙,有一个名为 HLS.js 的工具。 You can embed any stream with m3u8 extension with this tool, here it is the link: HLS.js
您可以使用此工具嵌入任何带有 m3u8 扩展名的 stream,这是链接: HLS.js
If your stream is insecure you need to use an http website if it's not you can use https .如果您的 stream 不安全,您需要使用http网站,如果不是,您可以使用https 。 I will give for you an example code:
我会给你一个示例代码:
<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>
If this extension can be played on any device the video will have the same source as your stream.如果此扩展程序可以在任何设备上播放,则视频将与您的 stream 具有相同的源。
Hope I have helped!希望我有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.