Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play html5 video play m3U8 on mobile and desktop?

I have HLS m3u8 that plays well on IOS and Android with html5 <video>

But does not play on desktop PC or desktop MAC (Chrome, Firefox)

How to play m3u8 on desktop PCs ?

Is there a streaming format of video that would play both on desktop and mobile ?

like image 201
yarek Avatar asked Apr 30 '14 12:04

yarek


People also ask

How can I play M3U8 on my phone?

Even currently android builtin media player is able to play live urls inside an m3u8. Basically m3u8 is nothing else but text file to android. So you have to make m3u parser. If you are just looking for application, you can try and iptv which is free to use.

How do I stream M3U8 in HTML?

Stream HLS or m3u8 files using above code. it works for desktop: ms edge browser (not working with desktop chrome) and mobile: chrome,opera mini browser. if you want to play direct . m3u8 (HLS file), then add chrome extension called Native HLS Playback from chrome web app.

How can I play M3U8 file in browser?

Just open Microsoft Edge and write the url of the m3u8 file and it will start playing.

How can I play M3U8 videos on my PC?

How to open an M3U8 file. You can open an M3U8 file and play the playlist it contains in many media players, including Microsoft Windows Media Player (Windows) and VideoLAN VLC media player (multiplatform).


1 Answers

take a look on hls.js project at https://github.com/video-dev/hls.js/ it solves exactly this problem.

here's a small sample on how to use it.

<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<video id="video"></video>
<script>
  if(Hls.isSupported()) {
    var video = document.getElementById('video');
    var hls = new Hls();
    hls.loadSource('https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8');
    hls.attachMedia(video);
    hls.on(Hls.Events.MANIFEST_PARSED,function() {
      video.play();
  });
 }
</script>

once the manifest is parsed, you can use all the regular events, properties and method of the original html5 video element.

you may find their demo here: https://video-dev.github.io/hls.js/demo/

like image 94
Roey Avatar answered Sep 19 '22 16:09

Roey