A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
add ambient mode to videos
aminnausin4b561a53088d
diff --git a/resources/js/components/video/VideoAmbientPlayer.vue b/resources/js/components/video/VideoAmbientPlayer.vuenew file mode 100644index 00000000..ca8c44f3--- /dev/null+++ b/resources/js/components/video/VideoAmbientPlayer.vue@@ -0,0 +1,70 @@+<script setup>+import VideoPlayer from './VideoPlayer.vue';++import { storeToRefs } from 'pinia';+import { useAppStore } from '../../stores/AppStore';+import { onMounted, onUnmounted, ref } from 'vue';++const player = ref(null)+const step = ref(undefined);+const canvas = ref(null);+const ctx = ref(null);++const appStore = useAppStore();+const { lightMode, ambientMode } = storeToRefs(appStore);++const draw = () => {+ console.log('draw');++ if(!player.value || !lightMode || !canvas.value){+ drawPause();+ return;+ }++ ctx.value.drawImage(player?.value, 0, 0, canvas.value?.width, canvas.value?.height)+}++const drawLoop = () => {+ draw();+ step.value = window.requestAnimationFrame(drawLoop);+};++const drawPause = () => {+ if(!step.value) return++ window.cancelAnimationFrame(step.value);+ step.value = undefined;+};++onMounted(() => {+ ctx.value = canvas.value?.getContext("2d")+ // ctx.value.filter = "blur(1px)";+ player.value = document.getElementById('vid-source');+})++onUnmounted(() => {+ drawPause();+})+</script>++<template>+ <span v-show="!lightMode && ambientMode" class="flex flex-wrap lg:flex-nowrap snap-y w-full absolute left-0 gap-6 -mt-9 pt-2">+ <section class="w-full lg:w-1/6 lg:max-w-72 sm:min-w-32 shrink-0 hidden lg:block h-0">+ </section>+ <section class="flex w-full z-10 rounded-2xl px-6 aspect-video">+ <canvas width="10" height="6" aria-hidden="true"+ class="w-full opacity-100 h-full p-8 blur-lg" ref="canvas">+ Canvas+ </canvas>+ </section>+ <section class="w-full lg:w-1/6 lg:max-w-72 sm:min-w-32 shrink-0 hidden lg:block h-0">+ </section>+ </span>+ <VideoPlayer class="z-10"+ @loadedData="draw"+ @seeked="draw"+ @play="drawLoop"+ @pause="drawPause"+ @ended="drawPause"+ />+</template>\ No newline at end of filediff --git a/resources/js/components/video/VideoInfoPanel.vue b/resources/js/components/video/VideoInfoPanel.vueindex 2162636c..55267735 100644--- a/resources/js/components/video/VideoInfoPanel.vue+++ b/resources/js/components/video/VideoInfoPanel.vue@@ -58,7 +58,7 @@ watch(() => stateVideo.value, handlePropsUpdate, { immediate: true, deep: true }<template><div- class="p-6 w-full mx-auto dark:bg-primary-dark-800 bg-primary-800 rounded-xl shadow-lg flex justify-center sm:justify-between gap-4 flex-wrap sm:flex-nowrap overflow-hidden">+ class="p-6 w-full mx-auto dark:bg-primary-dark-800/70 bg-primary-800 rounded-xl shadow-lg flex justify-center sm:justify-between gap-4 flex-wrap sm:flex-nowrap overflow-hidden"><div id="mp4-description" class="flex items-center gap-4 w-full md:w-2/3 "><img id="folder-thumbnail" class="h-28 object-contain rounded-md shadow-md":src="stateVideo?.attributes?.thumbnail?.url ?? 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'"diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vueindex dc9e86ba..f907a07a 100644--- a/resources/js/components/video/VideoPlayer.vue+++ b/resources/js/components/video/VideoPlayer.vue@@ -1,10 +1,11 @@+<!-- eslint-disable no-unused-vars --><script setup>import { storeToRefs } from 'pinia';import { useContentStore } from '../../stores/ContentStore';import { computed, ref, watch } from 'vue';// Heatmap can be composable-const heatMapData = ref([{ x: 25, y: 60 }, { x: 154, y: 48 }, { x: 266, y: 12 }, { x: 585, y: 18 },{ x: 799, y: 16 }, { x: 1000, y: 100 }]);+const heatMapData = ref([{ x: 25, y: 60 }, { x: 154, y: 48 }, { x: 266, y: 12 }, { x: 585, y: 18 }, { x: 799, y: 16 }, { x: 1000, y: 100 }]);const heatMap = computed(() => {const start = 'M 0.0,100.0 ';@@ -88,30 +89,108 @@ const ContentStore = useContentStore();const { stateVideo } = storeToRefs(ContentStore);const { createRecord, updateViewCount } = ContentStore;+const emit = defineEmits(['loadedData', 'seeked', 'play', 'pause', 'ended']);+const initVideoPlayer = () => {let root = document.getElementById('root');root.scrollIntoView();}-const playVideo = () => {- if(currentID.value === stateVideo.value.id) return; // stop recording every time video seek+const handlePlayVideo = () => {+ if (currentID.value === stateVideo.value.id) return; // stop recording every time video seekcurrentID.value = stateVideo.value.id;createRecord(stateVideo.value.id);updateViewCount(stateVideo.value.id);}+const handlePlayerSeeked = () => {+ // add heatmap data ?+ emit('seeked');+}++//#region Player Events++const onPlayerPlay = (event) => {+ // console.log(event.type);+ // player.setPlaying(true);+ handlePlayVideo();+ emit('play');+};++const onPlayerPause = (event) => {+ // console.log(event.type);+ // player.setPlaying(false);+ emit('pause');+};++const onPlayerEnded = (event) => {+ // console.log(event.type);+ // player.setPlaying(false);+ emit('ended');+};++const onPlayerLoadeddata = (event) => {+ // console.log(event.type);+ emit('loadedData');+};++const onPlayerWaiting = (event) => {+ // console.log(event.type);+};++const onPlayerPlaying = (event) => {+ // console.log(event.type);+};++const onPlayerTimeupdate = (event) => {+ // console.log({ event: event.type, time: event.target.currentTime });+};++const onPlayerCanplay = (event) => {+ // console.log(event.type);+};++const onPlayerCanplaythrough = (event) => {+ // console.log(event.type);+};++const onPlayerSeek = (event) => {+ // console.log(event.type);+ handlePlayerSeeked();+};+++const playerStateChanged = (event) => {+ // console.log(event.type);+};++//#endregion+watch(stateVideo, initVideoPlayer)</script><template><div class="relative group rounded-md overflow-clip">- <video id="vid-source" width="100%" :src="stateVideo?.attributes?.path ? `../${stateVideo?.attributes?.path}` : ''" type="video/mp4" controls- class="focus:outline-none aspect-video flex" @play="playVideo" ref="player">+ <video id="vid-source" width="100%"+ :src="stateVideo?.attributes?.path ? `../${stateVideo?.attributes?.path}` : ''" type="video/mp4" controls+ class="focus:outline-none aspect-video flex"+ ref="player"+ @play="onPlayerPlay"+ @pause="onPlayerPause"+ @ended="onPlayerEnded"+ @loadeddata="onPlayerLoadeddata"+ @waiting="onPlayerWaiting"+ @playing="onPlayerPlaying"+ @timeupdate="onPlayerTimeupdate"+ @canplay="onPlayerCanplay"+ @canplaythrough="onPlayerCanplaythrough"+ @statechanged="playerStateChanged"+ @seeked="onPlayerSeek"><track kind="captions"></video><section class="absolute bottom-6 w-full hidden px-[1.5%]"> <!-- group-hover:block -->- <svg class="ytp-heat-map-svg fill-indigo-200/70" height="100%" preserveAspectRatio="none" version="1.1" viewBox="0 0 1000 100"- width="100%" style="height: 40px;">+ <svg class="ytp-heat-map-svg fill-indigo-200/70" height="100%" preserveAspectRatio="none" version="1.1"+ viewBox="0 0 1000 100" width="100%" style="height: 40px;"><defs><!-- <clipPath id="4"><path class="ytp-heat-map-path"@@ -122,8 +201,7 @@ watch(stateVideo, initVideoPlayer)<path class="ytp-heat-map-path" :d="heatMap"></path></clipPath></defs>- <rect class="ytp-heat-map-graph" clip-path="url(#4)" height="100%"- width="100%" x="0" y="0"></rect>+ <rect class="ytp-heat-map-graph" clip-path="url(#4)" height="100%" width="100%" x="0" y="0"></rect><rect class="ytp-heat-map-hover" clip-path="url(#4)" fill="white" fill-opacity="0.7" height="100%"width="100%" x="0" y="0"></rect><rect class="ytp-heat-map-play" clip-path="url(#4)" height="100%" x="0" y="0"></rect>diff --git a/resources/js/layouts/LayoutBase.vue b/resources/js/layouts/LayoutBase.vueindex 9e4f1b31..5182cec8 100644--- a/resources/js/layouts/LayoutBase.vue+++ b/resources/js/layouts/LayoutBase.vue@@ -12,12 +12,12 @@ const { selectedSideBar } = storeToRefs(appStore);<section id="left-card" class="w-full p-3 pb-6 rounded-2xl lg:w-1/6 lg:max-w-72 sm:min-w-32 shrink-0 space-y-2 scroll-mt-6 hidden lg:block"></section><section id="content-card"- class="bg-primary-900 dark:bg-primary-dark-900 dark:text-[#e2e0e2] shadow-xl p-6 pt-3 rounded-2xl w-full flex flex-col gap-3">- <NavBar />- <slot name="content"></slot>+ class="bg-primary-900 dark:bg-primary-dark-900 dark:text-[#e2e0e2] shadow-xl p-6 pt-3 rounded-2xl w-full flex flex-col gap-3 z-20">+ <NavBar class="z-20" />+ <slot name="content" class="relative z-0"></slot></section><section id="list-card" :class="{ invisible: !selectedSideBar }"- class="bg-primary-900 dark:bg-primary-dark-900 dark:text-[#e2e0e2] shadow-xl p-3 pb-6 rounded-2xl w-full lg:w-1/6 lg:max-w-72 sm:min-w-32 shrink-0 space-y-2 scroll-mt-6">+ class="bg-primary-900 dark:bg-primary-dark-900 dark:text-[#e2e0e2] shadow-xl p-3 pb-6 rounded-2xl w-full lg:w-1/6 lg:max-w-72 sm:min-w-32 shrink-0 space-y-2 scroll-mt-6 z-20"><slot name="sidebar"></slot></section></main>diff --git a/resources/js/views/VideoView.vue b/resources/js/views/VideoView.vueindex 1ec17983..22cfe761 100644--- a/resources/js/views/VideoView.vue+++ b/resources/js/views/VideoView.vue@@ -1,8 +1,8 @@<script setup>+import VideoAmbientPlayer from '../components/video/VideoAmbientPlayer.vue';+import VideoInfoPanel from '../components/video/VideoInfoPanel.vue';import VideoSidebar from '../components/panels/VideoSidebar.vue';import LayoutBase from '../layouts/LayoutBase.vue';-import VideoPlayer from '../components/video/VideoPlayer.vue';-import VideoInfoPanel from '../components/video/VideoInfoPanel.vue';import VideoCard from '../components/cards/VideoCard.vue';import TableBase from '../components/table/TableBase.vue';@@ -101,8 +101,9 @@ watch(() => selectedSideBar.value, cycleSideBar, { immediate: false });<LayoutBase><template v-slot:content><section id="content-video" class="flex flex-col gap-3">+<div id="video-container" class="flex flex-col gap-3">- <VideoPlayer />+ <VideoAmbientPlayer/><!-- <hr class=""> -->