From 19ff2af29b4d86215054d4811216a8e4b6cebe3b Mon Sep 17 00:00:00 2001 From: prayag17 Date: Fri, 26 May 2023 15:16:30 +0530 Subject: [PATCH] More updates to player and fixed some ui stuff --- public/splash.html | 5 -- src/App.jsx | 8 ++- src/components/layouts/artist/artistAlbum.jsx | 9 ++- src/components/utils/iconsCollection.jsx | 1 + src/routes/home/home.module.scss | 2 +- src/routes/item/index.jsx | 16 ++--- src/routes/item/item.module.scss | 1 + src/routes/player/videoPlayer.jsx | 59 +++++++++++++++++-- src/utils/hooks/useKeyPress.jsx | 32 ++++++++++ 9 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 src/utils/hooks/useKeyPress.jsx diff --git a/public/splash.html b/public/splash.html index 8e9645c..a02cb91 100644 --- a/public/splash.html +++ b/public/splash.html @@ -90,11 +90,6 @@ transform: scaleX(1) translateX(100%); transform-origin: left; } - - /* 100% { - transform: scaleX(0) translateX(-100%); - transform-origin: left; - } */ } diff --git a/src/App.jsx b/src/App.jsx index 36b8fd2..ce10953 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,6 +1,8 @@ /** @format */ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; + +import { appWindow } from "@tauri-apps/api/window"; import Konami from "react-konami-code"; // @ts-ignore @@ -272,6 +274,10 @@ function App() { setEasterEgg(true); }; + useEffect(() => { + appWindow.setFullscreen(false); + }, [location]); + return ( diff --git a/src/components/layouts/artist/artistAlbum.jsx b/src/components/layouts/artist/artistAlbum.jsx index 48c7f88..9fc4589 100644 --- a/src/components/layouts/artist/artistAlbum.jsx +++ b/src/components/layouts/artist/artistAlbum.jsx @@ -19,8 +19,11 @@ import { Link } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; -import { MdiClockOutline } from "../../icons/mdiClockOutline"; +import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; + import { getRuntimeMusic } from "../../../utils/date/time"; + +import { MdiClockOutline } from "../../icons/mdiClockOutline"; import { MdiHeart } from "../../icons/mdiHeart"; import { MdiHeartOutline } from "../../icons/mdiHeartOutline"; import { MdiAlbum } from "../../icons/mdiAlbum"; @@ -44,12 +47,12 @@ export const ArtistAlbum = ({ user, album, boxProps }) => { let result; if (track.UserData.IsFavorite) { result = await getUserLibraryApi(window.api).unmarkFavoriteItem({ - userId: user.data.Id, + userId: user.Id, itemId: track.Id, }); } else if (!track.UserData.IsFavorite) { result = await getUserLibraryApi(window.api).markFavoriteItem({ - userId: user.data.Id, + userId: user.Id, itemId: track.Id, }); } diff --git a/src/components/utils/iconsCollection.jsx b/src/components/utils/iconsCollection.jsx index 574845f..abd3603 100644 --- a/src/components/utils/iconsCollection.jsx +++ b/src/components/utils/iconsCollection.jsx @@ -62,6 +62,7 @@ export const MediaTypeIconCollection = { Photo: , Book: , MusicAlbum: , + AudioBook: , }; export const TypeIconCollectionCard = { diff --git a/src/routes/home/home.module.scss b/src/routes/home/home.module.scss index 3861e6a..5c90746 100644 --- a/src/routes/home/home.module.scss +++ b/src/routes/home/home.module.scss @@ -84,7 +84,7 @@ -webkit-line-clamp: 2; margin-bottom: 0.5em; &-logo { - max-width: 10em; + max-width: 12em; height: 2em; object-fit: contain; object-position: bottom; diff --git a/src/routes/item/index.jsx b/src/routes/item/index.jsx index 6108df1..4538a75 100644 --- a/src/routes/item/index.jsx +++ b/src/routes/item/index.jsx @@ -505,9 +505,9 @@ const ItemDetail = () => { setAudioTracks(audios); setSubtitleTracks(subs); - setCurrentVideoTrack(videos[0].DisplayTitle); - setCurrentAudioTrack(audios[0].DisplayTitle); - setCurrentSubTrack(subs[0].DisplayTitle); + setCurrentVideoTrack(videos[0]?.DisplayTitle); + setCurrentAudioTrack(audios[0]?.DisplayTitle); + setCurrentSubTrack(subs[0]?.DisplayTitle); } }, [item.isSuccess]); @@ -1494,7 +1494,8 @@ const ItemDetail = () => { item.data.MediaStreams.length != 0 && ( <> - {videoTracks != [] && ( + {videoTracks.length != + 0 && ( { )} - {audioTracks != [] && ( + {audioTracks.length != + 0 && ( { )} - {subtitleTracks != - [] && ( + {subtitleTracks.length != + 0 && ( { const navigate = useNavigate(); const [url, startPosition, itemDuration, itemId, itemName] = @@ -50,11 +52,12 @@ export const VideoPlayer = () => { const [showControls, setShowControls] = useState(false); const playerRef = useRef(); + const [isBuffering, setIsBuffering] = useState(true); const [isPlaying, setIsPlaying] = useState(true); const [isMuted, setIsMuted] = useState(false); const [isReady, setIsReady] = useState(false); const [isPIP, setIsPIP] = useState(false); - const [volume, setVolume] = useState(0.75); + const [volume, setVolume] = useState(0.8); const [showVolume, setShowVolume] = useState(false); @@ -73,6 +76,7 @@ export const VideoPlayer = () => { const onProgress = async (e) => { setProgress(e.played); + setCurrentTime(secToTicks(e.playedSeconds)); await getPlaystateApi(window.api).reportPlaybackProgress({ playbackProgressInfo: { ItemId: itemId, @@ -132,6 +136,26 @@ export const VideoPlayer = () => { } }, [showControls]); + const handleKeyPress = useCallback((event) => { + switch (event.key) { + case "ArrowRight": + playerRef.current.seekTo( + playerRef.current.getCurrentTime() + 15, + ); + break; + case "ArrowLeft": + playerRef.current.seekTo( + playerRef.current.getCurrentTime() - 15, + ); + break; + case "p": + setIsPlaying(!isPlaying); + default: + console.log(event.key); + break; + } + }, []); + return ( { setShowControls(true); }} > + + + { backdropFilter: "blur(5px)", padding: 1, borderRadius: "10px", + border: "1px solid rgb(255 255 255 / 0.15)", + boxShadow: + "0 0 10px rgb(0 0 0 / 0.4) ", transform: "translatey(-120%) scale(0)", "&:before": { display: "none" }, @@ -293,7 +333,13 @@ export const VideoPlayer = () => { onMouseOut={() => setShowVolume(false)} padding="0.25em 1em" > - + { padding: 1, borderRadius: "10px", + border: "1px solid rgb(255 255 255 / 0.15)", + boxShadow: + "0 0 10px rgb(0 0 0 / 0.4) ", transform: "translatey(-120%) scale(0)", "&:before": { @@ -388,6 +437,8 @@ export const VideoPlayer = () => { muted={isMuted} pip={isPIP} volume={volume} + onBuffer={() => setIsBuffering(true)} + onBufferEnd={() => setIsBuffering(false)} /> ); diff --git a/src/utils/hooks/useKeyPress.jsx b/src/utils/hooks/useKeyPress.jsx new file mode 100644 index 0000000..88abcab --- /dev/null +++ b/src/utils/hooks/useKeyPress.jsx @@ -0,0 +1,32 @@ +/** @format */ +import { useState, useEffect } from "react"; + +const useKeyPress = (targetKey) => { + // State for keeping track of whether key is pressed + const [keyPressed, setKeyPressed] = useState(false); + // If pressed key is our target key then set to true + function downHandler({ key }) { + if (key === targetKey) { + setKeyPressed(true); + } + } + // If released key is our target key then set to false + const upHandler = ({ key }) => { + if (key === targetKey) { + setKeyPressed(false); + } + }; + // Add event listeners + useEffect(() => { + window.addEventListener("keydown", downHandler); + window.addEventListener("keyup", upHandler); + // Remove event listeners on cleanup + return () => { + window.removeEventListener("keydown", downHandler); + window.removeEventListener("keyup", upHandler); + }; + }, []); // Empty array ensures that effect is only run on mount and unmount + return keyPressed; +}; + +export default useKeyPress;