Experimental video player

This commit is contained in:
Aleksi Lassila
2023-06-19 20:44:36 +03:00
parent 3429d2c5ee
commit b39bf97b8a
21 changed files with 21264 additions and 146 deletions

View File

@@ -0,0 +1,48 @@
<script lang="ts">
import { onMount } from 'svelte';
import { getJellyfinPlaybackInfo } from '$lib/jellyfin/jellyfin';
import Hls from 'hls.js';
import Modal from '../Modal/Modal.svelte';
import { JELLYFIN_BASE_URL } from '$lib/jellyfin/jellyfin.js';
export let visible = false;
export let jellyfinVideoId: string;
let video: HTMLVideoElement;
const { data: playbackInfo, load: loadPlaybackInfo } = getJellyfinPlaybackInfo();
onMount(() => {
if (!Hls.isSupported()) {
throw new Error('HLS is not supported');
}
if (!jellyfinVideoId) {
throw new Error('No video id provided');
}
loadPlaybackInfo(jellyfinVideoId);
});
playbackInfo.subscribe((info) => {
console.log('Subscribe info', info);
if (!info) return;
console.log(video.src);
const hls = new Hls();
hls.loadSource(JELLYFIN_BASE_URL + info);
hls.attachMedia(video);
});
function handleClose() {
visible = false;
video?.pause();
}
</script>
<Modal {visible} close={handleClose}>
<video controls bind:this={video} />
</Modal>