Skip to content

A self-hosted media server and file management system

play pause

aminnausin1f7512836cb4
diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vue
index c5adbbc7..794bfe2a 100755
--- a/resources/js/components/video/VideoPlayer.vue
+++ b/resources/js/components/video/VideoPlayer.vue
@@ -3,7 +3,7 @@
import type { FolderResource, VideoResource } from '@/types/resources';
import type { Metadata, Series } from '@/types/model';
-import { computed, onMounted, onUnmounted, ref, watch, type Ref } from 'vue';
+import { computed, onMounted, onUnmounted, ref, useTemplateRef, watch, type Ref } from 'vue';
import { UseCreatePlayback } from '@/service/mutations';
import { useVideoPlayback } from '@/service/queries';
import { useContentStore } from '@/stores/ContentStore';
@@ -13,6 +13,9 @@ import { getMediaUrl } from '@/service/api';
import _ from 'lodash';
+import ProiconsPlay from '~icons/proicons/play';
+import CircumPause1 from '~icons/circum/pause-1';
+
const playbackDataBuffer = 5;
const defaultHeatMapData = [
{ x: 25, y: 60 },
@@ -29,6 +32,7 @@ const progressCache = ref<{ metadata_id: number; progress: number }[]>([]);
const metadata_id = ref<number>(NaN);
const currentID = ref(-1);
const isLoading = ref(true);
+const isPaused = ref(true);
const isAudio = computed(() => {
return stateVideo.value.metadata?.mime_type?.startsWith('audio') ?? false;
});
@@ -39,7 +43,7 @@ const audioPoster = computed(() => {
'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
);
});
-const player = ref<null | HTMLVideoElement>(null);
+const player = useTemplateRef('player');
// const url = ref('');
const { data: playbackData } = useVideoPlayback(metadata_id);
@@ -204,12 +208,14 @@ const onPlayerPlay = (event: any) => {
handlePlayVideo();
emit('play');
handleProgress();
+ isPaused.value = false;
};
const onPlayerPause = (event: any) => {
// console.log(event.type);
// player.setPlaying(false);
emit('pause');
+ isPaused.value = true;
};
const onPlayerEnded = (event: any) => {
@@ -278,6 +284,11 @@ const handleVolumeChange = () => {
debouncedCacheVolume();
};
+const handleManualPlay = () => {
+ if (player.value?.paused) player.value.play();
+ else player.value?.pause();
+};
+
watch(stateVideo, initVideoPlayer);
onMounted(() => {
@@ -303,13 +314,7 @@ defineExpose({
</script>
<template>
- <div class="relative group rounded-xl overflow-clip">
- <div
- v-if="isAudio"
- id="audio-poster"
- class="absolute top-0 left-0 w-full h-full blur"
- :style="`background: transparent url('${audioPoster}') 50% 50% / cover no-repeat`"
- ></div>
+ <div :class="`relative group rounded-xl overflow-clip`">
<video
id="vid-source"
width="100%"
@@ -318,7 +323,7 @@ defineExpose({
ref="player"
style="z-index: 3"
:src="stateVideo?.path ? `../${stateVideo?.path}` : ''"
- :class="`relative focus:outline-none flex object-contain ${isLoading || !stateVideo?.path ? 'aspect-video' : isAudio ? 'max-h-[60vh]' : ''}`"
+ :class="`relative focus:outline-none object-contain hover:cursor-pointer ${isLoading || !stateVideo?.path ? 'aspect-video' : isAudio ? 'max-h-[60vh]' : ''}`"
:poster="isAudio ? audioPoster : ''"
@play="onPlayerPlay"
@pause="onPlayerPause"
@@ -333,9 +338,36 @@ defineExpose({
@statechanged="playerStateChanged"
@seeked="onPlayerSeek"
@volumechange="handleVolumeChange"
+ @click.stop="
+ () => {
+ if (isAudio) handleManualPlay();
+ }
+ "
>
<track kind="captions" />
</video>
+ <div
+ v-if="isAudio"
+ id="audio-poster"
+ class="absolute top-0 left-0 w-full h-full blur cursor-pointer flex items-center justify-center"
+ :style="`background: transparent url('${audioPoster}') 50% 50% / cover no-repeat`"
+ ></div>
+ <section class="w-fit h-fit absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2" style="z-index: 4">
+ <button
+ :class="`aspect-square opacity-0 group-hover:opacity-100 transition-opacity hover:text-purple-600 bg-white/70 hover:bg-white/90 dark:bg-neutral-900/70 dark:hover:bg-neutral-900/90 rounded-full p-3 xs:p-4 drop-shadow-lg`"
+ @click.stop="
+ () => {
+ if (isAudio) handleManualPlay();
+ }
+ "
+ title="Play/Pause"
+ type="button"
+ v-if="player"
+ >
+ <ProiconsPlay :class="`xs:w-8 xs:h-8 aspect-square [&>*]:!stroke-1`" v-show="isPaused" />
+ <CircumPause1 :class="`xs:w-8 xs:h-8 aspect-square`" v-show="!isPaused" />
+ </button>
+ </section>
<section
style="z-index: 4"
:class="`absolute ${isAudio ? 'bottom-[52px] z-20 rounded-sm overflow-clip' : 'bottom-6'} w-[94.95%] m-auto left-0 right-0 opacity-0 group-hover:opacity-65 transition-opacity duration-75 h-5 pointer-events-none`"