provide hlsindex for the api

This commit is contained in:
deflax 2021-10-12 16:46:24 +00:00
parent 08af44ffde
commit ee82c7082c
4 changed files with 19 additions and 11 deletions

View file

@ -21,12 +21,12 @@ def start():
) )
return page return page
@frontend.route("/player/<appname>/<streamname>") @frontend.route("/player/<appname>/<hlsindex>")
def show_player(appname, streamname): def show_player(appname, hlsindex):
playerTemplate = '%s/player.html.j2' % zomstream.configuration['template_folder'] playerTemplate = '%s/player.html.j2' % zomstream.configuration['template_folder']
page = flask.render_template( page = flask.render_template(
playerTemplate, playerTemplate,
streamname=streamname, hlsindex=hlsindex,
appname=appname, appname=appname,
configuration=zomstream.configuration configuration=zomstream.configuration
) )

View file

@ -18,7 +18,7 @@
{% endif %} {% endif %}
{% for item in items %} {% for item in items %}
<article> <article>
<h1>{{ item[1] }}</h1> <h1>Stream {{ item[1] }}</h1>
<table> <table>
<tbody> <tbody>
<tr> <tr>
@ -27,20 +27,26 @@
<th></th> <th></th>
</tr> </tr>
<tr> <tr>
<td>RTMP url</td> <td>RTMP substream {{ item[2] }}</td>
<td><em class="url">rtmp://{{ configuration["rtmp_base"] }}/{{ item[0] }}/{{ item[1] }}</em></td> <td><em class="url">rtmp://{{ configuration["rtmp_base"] }}/{{ item[0] }}/{{ item[2] }}</em></td>
<td class="btn"><a href="rtmp://{{ configuration['rtmp_base'] }}/{{ item[0] }}/{{ item[1] }}" class="btn btn-red">&#9654;<br/>RTMP</a></td> <td class="btn"><a href="rtmp://{{ configuration['rtmp_base'] }}/{{ item[0] }}/{{ item[2] }}" class="btn btn-red">&#9654;<br/>RTMP</a></td>
</tr> </tr>
<tr> <tr>
<td>HLS m3u8</td> <td>HLS m3u8</td>
<td><em class="url">{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/hls/{{ item[1] }}/index.m3u8</em></td> <td><em class="url">{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/hls/{{ item[1] }}/index.m3u8</em></td>
<!-- <td class="btn"><a href="{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/player/{{ item[1] }}" class="btn btn-green">&#9654;<br/>HLS.js</a></td> --> <!-- <td class="btn"><a href="{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/player/{{ item[1] }}" class="btn btn-green">&#9654;<br/>HLS.js</a></td> -->
<td class="btn"><a href="{{ url_for('frontend.show_player', streamname=item[1], appname=item[0]) }}" class="btn btn-green">&#9654;<br/>HLS.js</a></td> <td class="btn"><a href="{{ url_for('frontend.show_player', appname=item[0], hlsindex=item[1]) }}" class="btn btn-green">&#9654;<br/>HLS.js</a></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</article> </article>
{% endfor %} {% endfor %}
<a href="{{ url_for('frontend.show_player', streamname=item[1], appname=item[0]) }}"
class="btn-large btn-green">
&#9655; Web Player
</a>
</main> </main>
<footer> <footer>
{{ configuration["footer"] }} {{ configuration["footer"] }}

View file

@ -22,7 +22,7 @@
var hls = new Hls({ var hls = new Hls({
debug: true, debug: true,
}); });
hls.loadSource("{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/hls/{{ streamname }}/index.m3u8"); hls.loadSource("{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/hls/{{ hlsindex }}.m3u8");
hls.attachMedia(video); hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, function () { hls.on(Hls.Events.MEDIA_ATTACHED, function () {
video.muted = true; video.muted = true;
@ -33,7 +33,7 @@
// 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 throught the `src` property. // 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 throught the `src` property.
// This is using the built-in support of the plain video element, without using hls.js. // This is using the built-in support of the plain video element, without using hls.js.
else if (video.canPlayType('application/vnd.apple.mpegurl')) { else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = "{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/hls/{{ streamname }}/index.m3u8"; video.src = "{{ configuration['web_proto'] }}://{{ configuration['base_url'] }}/hls/{{ hlsindex }}.m3u8";
video.addEventListener('canplay', function () { video.addEventListener('canplay', function () {
video.play(); video.play();
}); });

View file

@ -40,8 +40,10 @@ class Zomstream:
for stream in streams: for stream in streams:
name = stream.find('name') name = stream.find('name')
rate = stream.find('bw_video') rate = stream.find('bw_video')
streamname = name.text
hlsindex = streamname.split('_'[0]
if rate.text != "0": if rate.text != "0":
self.streamnames.append( [appname.text, name.text] ) self.streamnames.append( [appname.text, hlsindex, streamname] )
return self.streamnames return self.streamnames