71 lines
1.2 KiB
Vue
71 lines
1.2 KiB
Vue
<template>
|
|
<div :class="$style.container">
|
|
<iframe
|
|
id="yt-player"
|
|
ref="iframe"
|
|
:class="$style.iframe"
|
|
width="100%"
|
|
height="100%"
|
|
:src="url.href"
|
|
frameborder="0"
|
|
allow="
|
|
accelerometer;
|
|
autoplay;
|
|
encrypted-media;
|
|
gyroscope;
|
|
picture-in-picture;
|
|
fullscreen;
|
|
"
|
|
>
|
|
</iframe>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { onMounted, ref, useTemplateRef } from "vue";
|
|
|
|
const props = defineProps<{ id: string; title?: string }>();
|
|
|
|
defineExpose({ seekTo, requestFullscreen });
|
|
|
|
const url = new URL("https://www.youtube.com/embed/" + props.id);
|
|
url.searchParams.set("enablejsapi", "1");
|
|
|
|
const player = ref();
|
|
const iframe = useTemplateRef("iframe");
|
|
|
|
onMounted(() => {
|
|
const { YT } = window as any;
|
|
if (YT?.Player) {
|
|
player.value = new YT.Player("yt-player");
|
|
}
|
|
});
|
|
|
|
function seekTo(t: number) {
|
|
if (player.value) {
|
|
player.value.seekTo(t, true);
|
|
}
|
|
}
|
|
|
|
function requestFullscreen() {
|
|
if (iframe.value) {
|
|
iframe.value.requestFullscreen();
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style module>
|
|
.container {
|
|
padding-bottom: 56.25%;
|
|
position: relative;
|
|
}
|
|
|
|
.iframe {
|
|
position: absolute;
|
|
top: 0px;
|
|
left: 0px;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
</style>
|