admin管理员组文章数量:1312692
I wish to stream live video in my https website from this http site.
Added reference of hls.min.js into my template. Copy-pasted their code:
<video id="video" width="320" height="240" controls autoplay
class="videoCentered"></video>
<script>
if(Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
hls.loadSource('/hls/metsis.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
</script>
into my template, but the player doesn't start to stream. browser console says:
Uncaught ReferenceError: Hls is not defined
Where exactly is reference error? Here?
hls.loadSource('/hls/metsis.m3u8');
I wish to stream live video in my https website from this http site.
Added reference of hls.min.js into my template. Copy-pasted their code:
<video id="video" width="320" height="240" controls autoplay
class="videoCentered"></video>
<script>
if(Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
hls.loadSource('/hls/metsis.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
</script>
into my template, but the player doesn't start to stream. browser console says:
Uncaught ReferenceError: Hls is not defined
Where exactly is reference error? Here?
hls.loadSource('/hls/metsis.m3u8');
Share
Improve this question
asked Mar 20, 2018 at 9:55
GallexGallex
3213 gold badges8 silver badges19 bronze badges
3 Answers
Reset to default 4correct working code:
<script src="https://cdn.jsdelivr/npm/hls.js@latest"></script>
<video id="video" width="100%" height="380" controls autoplay
class="videoCentered"></video>
<script>
if(Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
hls.loadSource('http://tv.eenet.ee/hls/metsis.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
</script>
but browser blocks it, because the content must be served over https
if my page is loaded over https.
You are getting this error as you are trying to access Hls without importing it. Please import it using the following way
<script src="https://cdn.jsdelivr/npm/hls.js@latest"></script>
A more detailed example can be seen at Getting Started section of HLS documentation
Also, Add the correct reference
hls.loadSource('https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8');
You need a crossorigin attribute to handle insecure urls...
crossOrigin="anonymous"
And a muted attribute so that autoplay will function...
muted
For HLS standard/patibility I would also add a type attribute...
type="application/x-mpegURL"
Putting it all together the HTML player bees...
<video id="video" type="application/x-mpegURL" crossOrigin="anonymous" class="videoCentered" width="100%" height="380" muted controls autoplay></video>
本文标签: javascriptStreaming live video in HTML5 and with HLSStack Overflow
版权声明:本文标题:javascript - Streaming live video in HTML5 and with HLS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741897605a2403670.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论