Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HLS Stream Embed
#1
The following will allow your users to embed HLS stream videos in their posts.

Regular Expression (regex site):
\[m3u8\](?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))\[/m3u8\]

Replacement:
<video id="video" width="800" height="600" controls autoplay 
class="videoCentered"></video>
<script src="https://cdn.jsdelivr.net/hls.js/latest/hls.js"></script>
<script>
  if(Hls.isSupported()) {
    var video = document.getElementById('video');
    var  hls = new Hls({ autoStartLoad:false });
    hls.loadSource('$1');
    hls.attachMedia(video);
 hls.startLoad(1);
    hls.on(Hls.Events.MANIFEST_PARSED,function() {
  hls.startLoad(20);
      video.play();
  });
 }
</script>

Test Value:
[m3u8]https://nn.geo.joj.sk/live/hls/jojplus-360.m3u8[/m3u8]

To allow users to set auto play and mute options you will need to adapt the code.
Reply
#2
I tested it but I couldn't play anything on the forum ( its ok on admin cp) . i checking the page source . the $1 can't loading ( hls.loadSource('') ) .
its my page source :
	<div class="post_body scaleimages" id="pid_135408"><video id="video" width="800" height="600" controls autoplay <br />
class="videoCentered"></video><br />
<script src="https://cdn.jsdelivr.net/hls.js/latest/hls.js"></script><br />
<script><br />
  if(Hls.isSupported()) {<br />
    var video = document.getElementById('video');<br />
    var  hls = new Hls({ autoStartLoad:false });<br />
    hls.loadSource('');<br />
    hls.attachMedia(video);<br />
 hls.startLoad(1);<br />
    hls.on(Hls.Events.MANIFEST_PARSED,function() {<br />
  hls.startLoad(20);<br />
      video.play();<br />
  });<br />
 }<br />
</script>
Reply
#3
What is the URL you used? Try the following as the regular expression.
\[m3u8\](https?\://[^\r\n"<>&]+?)\[/m3u8\]
Reply
#4
(01-28-2019, 09:25 PM)Omar G. Wrote: What is the URL you used? Try the following as the regular expression.
\[m3u8\](https?\://[^\r\n"<>&]+?)\[/m3u8\]
I use this :
https://dmu3sqri.rocketcdn.com/kraldijital-akustiktv.smil/chunklist_b2328000.m3u8
I think the problem is from javascript handle . because there is an error
   
but it is strange why It doesn't problem with admin panel !
Reply
#5
It is weird because it should output the URL regardless of the JS not working. If the regex isn't recognizing the URL inside the [m3u8] tag then it should output nothing.
Reply
#6
There seems to be some issues with the code itself. Get a new HLS library, one that doesn't rely on IDs for starters.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)