hls.js tweaks
This commit is contained in:
parent
2c5818e315
commit
1c2e9529f0
33
index.html
33
index.html
@ -79,7 +79,7 @@
|
||||
<body>
|
||||
<img alt='banana' id='banana' src='banana.png'/>
|
||||
<img alt='bonzi' id='bonzi' src='bonzi.png'/>
|
||||
<video autoplay controls height='360px' playsinline id='live' width='640px'>
|
||||
<video autoplay controls height='360' id='live' playsinline width='640'>
|
||||
</video>
|
||||
<script src="https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js"></script>
|
||||
<script>
|
||||
@ -162,26 +162,20 @@
|
||||
})();
|
||||
|
||||
['mousemove', 'touchstart', 'touchmove'].forEach(type => {
|
||||
window.addEventListener(type, event => {
|
||||
mouseTop = event.clientY || event.touches[0].clientY;
|
||||
mouseLeft = event.clientX || event.touches[0].clientX;
|
||||
banana.style.top = `${mouseTop}px`;
|
||||
banana.style.left = `${mouseLeft}px`;
|
||||
});
|
||||
window.addEventListener(type, event => {
|
||||
mouseTop = event.clientY ?? event.touches[0]?.clientY;
|
||||
mouseLeft = event.clientX ?? event.touches[0]?.clientX;
|
||||
banana.style.top = `${mouseTop}px`;
|
||||
banana.style.left = `${mouseLeft}px`;
|
||||
});
|
||||
});
|
||||
|
||||
//live
|
||||
const live = document.getElementById('live');
|
||||
const liveSrc = new URL('index.m3u8', socials.live.link).toString();
|
||||
|
||||
const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
|
||||
const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
|
||||
|
||||
// resize video if view width is smaller than frame
|
||||
if (parseInt(live.width, 10) > vw) {
|
||||
live.width = `${vw}px`;
|
||||
live.height = `${vw * (9 / 16)}px`;
|
||||
}
|
||||
const vw = Math.max(document.documentElement.clientWidth ?? 0, window.innerWidth ?? 0);
|
||||
const vh = Math.max(document.documentElement.clientHeight ?? 0, window.innerHeight ?? 0);
|
||||
|
||||
(function loadStream() {
|
||||
// remove stream if embedded
|
||||
@ -190,6 +184,12 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// resize video if view width is smaller than frame
|
||||
if (live.width > vw) {
|
||||
live.width = vw;
|
||||
live.height = vw * (9 / 16);
|
||||
}
|
||||
|
||||
if (Hls.isSupported()) {
|
||||
const hls = new Hls({
|
||||
maxLiveSyncPlaybackRate: 1.5,
|
||||
@ -197,7 +197,8 @@
|
||||
|
||||
hls.on(Hls.Events.ERROR, (event, data) => {
|
||||
if (data.fatal) {
|
||||
live.style.display = 'none';
|
||||
if(data?.response.code === 404)
|
||||
live.style.display = 'none';
|
||||
hls.destroy();
|
||||
}
|
||||
setTimeout(loadStream, 5000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user