feat: add video player slider bubble theming #337

This commit is contained in:
Prayag Prajapati committed 2024-09-07 00:01:13 +05:30
1 parent bdf8f483d5
commit 0e4e05722b
5 files changed
+970 -343

No files matched your search

+15 -15
View File
@@ -19,29 +19,29 @@
"@fontsource-variable/noto-sans": "^5.0.5", "@fontsource-variable/noto-sans": "^5.0.5",
"@jellyfin/sdk": "0.10.0", "@jellyfin/sdk": "0.10.0",
"@million/lint": "1.0.0-rc.84", "@million/lint": "1.0.0-rc.84",
"@mui/lab": "6.0.0-beta.8", "@mui/lab": "6.0.0-beta.9",
"@mui/material": "6.0.1", "@mui/material": "6.0.2",
"@react-spring/web": "^9.7.4", "@react-spring/web": "^9.7.4",
"@tanem/react-nprogress": "^5.0.51", "@tanem/react-nprogress": "^5.0.51",
"@tanstack/react-query": "^5.53.1", "@tanstack/react-query": "^5.55.0",
"@tanstack/react-query-devtools": "^5.53.1", "@tanstack/react-query-devtools": "^5.55.0",
"@tanstack/react-router": "^1.52.2", "@tanstack/react-router": "^1.56.1",
"@tanstack/react-virtual": "^3.10.6", "@tanstack/react-virtual": "^3.10.7",
"@tauri-apps/api": "2.0.0-beta.15", "@tauri-apps/api": "2.0.0-beta.15",
"@tauri-apps/plugin-clipboard-manager": "2.1.0-beta.5", "@tauri-apps/plugin-clipboard-manager": "2.1.0-beta.5",
"@tauri-apps/plugin-process": "2.0.0-rc.1", "@tauri-apps/plugin-process": "2.0.0-rc.1",
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#v2", "@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#v2",
"@tauri-apps/plugin-updater": "2.0.0-rc.1", "@tauri-apps/plugin-updater": "2.0.0-rc.2",
"@types/node": "^22.5.1", "@types/node": "^22.5.4",
"@types/react": "^18.3.5", "@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"axios": "^1.7.7", "axios": "^1.7.7",
"axios-tauri-api-adapter": "^0.2.2", "axios-tauri-api-adapter": "^0.2.2",
"blurhash": "^2.0.5", "blurhash": "^2.0.5",
"framer-motion": "^11.3.31", "framer-motion": "^11.5.4",
"jassub": "^1.7.17", "jassub": "^1.7.17",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"material-symbols": "^0.22.2", "material-symbols": "^0.23.0",
"million": "^3.1.11", "million": "^3.1.11",
"notistack": "^3.0.1", "notistack": "^3.0.1",
"react": "18.3.1", "react": "18.3.1",
@@ -63,15 +63,15 @@
"devDependencies": { "devDependencies": {
"@babel/plugin-proposal-optional-chaining-assign": "^7.24.7", "@babel/plugin-proposal-optional-chaining-assign": "^7.24.7",
"@biomejs/biome": "^1.8.3", "@biomejs/biome": "^1.8.3",
"@tanstack/router-cli": "^1.52.0", "@tanstack/router-cli": "^1.56.1",
"@tanstack/router-devtools": "^1.52.2", "@tanstack/router-devtools": "^1.56.1",
"@tanstack/router-vite-plugin": "^1.52.0", "@tanstack/router-vite-plugin": "^1.56.1",
"@tauri-apps/cli": "2.0.0-beta.22", "@tauri-apps/cli": "2.0.0-beta.22",
"@types/lodash": "^4.17.7", "@types/lodash": "^4.17.7",
"@vitejs/plugin-react": "^4.3.1", "@vitejs/plugin-react": "^4.3.1",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"sass": "^1.77.8", "sass": "^1.78.0",
"vite": "^5.4.2" "vite": "^5.4.3"
}, },
"license": "GPL-3.0-only" "license": "GPL-3.0-only"
} }
+495 -203
View File
File diff suppressed because it is too large. Load diff
+271 -28
View File
@@ -361,34 +361,277 @@ declare module '@tanstack/react-router' {
// Create and export the route tree // Create and export the route tree
export const routeTree = rootRoute.addChildren({ interface ApiLibraryRouteChildren {
IndexRoute, ApiLibraryIdRoute: typeof ApiLibraryIdRoute
ApiRoute: ApiRoute.addChildren({ }
ApiLibraryRoute: ApiLibraryRoute.addChildren({ ApiLibraryIdRoute }),
ApiLoginRoute: ApiLoginRoute.addChildren({ const ApiLibraryRouteChildren: ApiLibraryRouteChildren = {
ApiLoginListRoute, ApiLibraryIdRoute: ApiLibraryIdRoute,
ApiLoginManualRoute, }
ApiLoginUserIdUserNameRoute,
}), const ApiLibraryRouteWithChildren = ApiLibraryRoute._addFileChildren(
ApiSearchRoute: ApiSearchRoute.addChildren({ ApiSearchIndexRoute }), ApiLibraryRouteChildren,
ApiAlbumIdRoute, )
ApiArtistIdRoute,
ApiBoxsetIdRoute, interface ApiLoginRouteChildren {
ApiEpisodeIdRoute, ApiLoginListRoute: typeof ApiLoginListRoute
ApiItemIdRoute, ApiLoginManualRoute: typeof ApiLoginManualRoute
ApiPersonIdRoute, ApiLoginUserIdUserNameRoute: typeof ApiLoginUserIdUserNameRoute
ApiPlayerAudioRoute, }
ApiPlaylistIdRoute,
ApiSeriesIdRoute, const ApiLoginRouteChildren: ApiLoginRouteChildren = {
ApiFavoriteIndexRoute, ApiLoginListRoute: ApiLoginListRoute,
ApiHomeIndexRoute, ApiLoginManualRoute: ApiLoginManualRoute,
ApiPlayerIndexRoute, ApiLoginUserIdUserNameRoute: ApiLoginUserIdUserNameRoute,
}), }
ErrorCodeRoute,
SetupServerAddRoute, const ApiLoginRouteWithChildren = ApiLoginRoute._addFileChildren(
SetupServerErrorRoute, ApiLoginRouteChildren,
SetupServerListRoute, )
})
interface ApiSearchRouteChildren {
ApiSearchIndexRoute: typeof ApiSearchIndexRoute
}
const ApiSearchRouteChildren: ApiSearchRouteChildren = {
ApiSearchIndexRoute: ApiSearchIndexRoute,
}
const ApiSearchRouteWithChildren = ApiSearchRoute._addFileChildren(
ApiSearchRouteChildren,
)
interface ApiRouteChildren {
ApiLibraryRoute: typeof ApiLibraryRouteWithChildren
ApiLoginRoute: typeof ApiLoginRouteWithChildren
ApiSearchRoute: typeof ApiSearchRouteWithChildren
ApiAlbumIdRoute: typeof ApiAlbumIdRoute
ApiArtistIdRoute: typeof ApiArtistIdRoute
ApiBoxsetIdRoute: typeof ApiBoxsetIdRoute
ApiEpisodeIdRoute: typeof ApiEpisodeIdRoute
ApiItemIdRoute: typeof ApiItemIdRoute
ApiPersonIdRoute: typeof ApiPersonIdRoute
ApiPlayerAudioRoute: typeof ApiPlayerAudioRoute
ApiPlaylistIdRoute: typeof ApiPlaylistIdRoute
ApiSeriesIdRoute: typeof ApiSeriesIdRoute
ApiFavoriteIndexRoute: typeof ApiFavoriteIndexRoute
ApiHomeIndexRoute: typeof ApiHomeIndexRoute
ApiPlayerIndexRoute: typeof ApiPlayerIndexRoute
}
const ApiRouteChildren: ApiRouteChildren = {
ApiLibraryRoute: ApiLibraryRouteWithChildren,
ApiLoginRoute: ApiLoginRouteWithChildren,
ApiSearchRoute: ApiSearchRouteWithChildren,
ApiAlbumIdRoute: ApiAlbumIdRoute,
ApiArtistIdRoute: ApiArtistIdRoute,
ApiBoxsetIdRoute: ApiBoxsetIdRoute,
ApiEpisodeIdRoute: ApiEpisodeIdRoute,
ApiItemIdRoute: ApiItemIdRoute,
ApiPersonIdRoute: ApiPersonIdRoute,
ApiPlayerAudioRoute: ApiPlayerAudioRoute,
ApiPlaylistIdRoute: ApiPlaylistIdRoute,
ApiSeriesIdRoute: ApiSeriesIdRoute,
ApiFavoriteIndexRoute: ApiFavoriteIndexRoute,
ApiHomeIndexRoute: ApiHomeIndexRoute,
ApiPlayerIndexRoute: ApiPlayerIndexRoute,
}
const ApiRouteWithChildren = ApiRoute._addFileChildren(ApiRouteChildren)
interface FileRoutesByFullPath {
'/': typeof IndexRoute
'': typeof ApiRouteWithChildren
'/library': typeof ApiLibraryRouteWithChildren
'/login': typeof ApiLoginRouteWithChildren
'/search': typeof ApiSearchRouteWithChildren
'/error/$code': typeof ErrorCodeRoute
'/album/$id': typeof ApiAlbumIdRoute
'/artist/$id': typeof ApiArtistIdRoute
'/boxset/$id': typeof ApiBoxsetIdRoute
'/episode/$id': typeof ApiEpisodeIdRoute
'/item/$id': typeof ApiItemIdRoute
'/library/$id': typeof ApiLibraryIdRoute
'/login/list': typeof ApiLoginListRoute
'/login/manual': typeof ApiLoginManualRoute
'/person/$id': typeof ApiPersonIdRoute
'/player/audio': typeof ApiPlayerAudioRoute
'/playlist/$id': typeof ApiPlaylistIdRoute
'/series/$id': typeof ApiSeriesIdRoute
'/setup/server/add': typeof SetupServerAddRoute
'/setup/server/error': typeof SetupServerErrorRoute
'/setup/server/list': typeof SetupServerListRoute
'/favorite': typeof ApiFavoriteIndexRoute
'/home': typeof ApiHomeIndexRoute
'/player': typeof ApiPlayerIndexRoute
'/search/': typeof ApiSearchIndexRoute
'/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute
}
interface FileRoutesByTo {
'/': typeof IndexRoute
'': typeof ApiRouteWithChildren
'/library': typeof ApiLibraryRouteWithChildren
'/login': typeof ApiLoginRouteWithChildren
'/error/$code': typeof ErrorCodeRoute
'/album/$id': typeof ApiAlbumIdRoute
'/artist/$id': typeof ApiArtistIdRoute
'/boxset/$id': typeof ApiBoxsetIdRoute
'/episode/$id': typeof ApiEpisodeIdRoute
'/item/$id': typeof ApiItemIdRoute
'/library/$id': typeof ApiLibraryIdRoute
'/login/list': typeof ApiLoginListRoute
'/login/manual': typeof ApiLoginManualRoute
'/person/$id': typeof ApiPersonIdRoute
'/player/audio': typeof ApiPlayerAudioRoute
'/playlist/$id': typeof ApiPlaylistIdRoute
'/series/$id': typeof ApiSeriesIdRoute
'/setup/server/add': typeof SetupServerAddRoute
'/setup/server/error': typeof SetupServerErrorRoute
'/setup/server/list': typeof SetupServerListRoute
'/favorite': typeof ApiFavoriteIndexRoute
'/home': typeof ApiHomeIndexRoute
'/player': typeof ApiPlayerIndexRoute
'/search': typeof ApiSearchIndexRoute
'/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute
}
interface FileRoutesById {
'/': typeof IndexRoute
'/_api': typeof ApiRouteWithChildren
'/_api/library': typeof ApiLibraryRouteWithChildren
'/_api/login': typeof ApiLoginRouteWithChildren
'/_api/search': typeof ApiSearchRouteWithChildren
'/error/$code': typeof ErrorCodeRoute
'/_api/album/$id': typeof ApiAlbumIdRoute
'/_api/artist/$id': typeof ApiArtistIdRoute
'/_api/boxset/$id': typeof ApiBoxsetIdRoute
'/_api/episode/$id': typeof ApiEpisodeIdRoute
'/_api/item/$id': typeof ApiItemIdRoute
'/_api/library/$id': typeof ApiLibraryIdRoute
'/_api/login/list': typeof ApiLoginListRoute
'/_api/login/manual': typeof ApiLoginManualRoute
'/_api/person/$id': typeof ApiPersonIdRoute
'/_api/player/audio': typeof ApiPlayerAudioRoute
'/_api/playlist/$id': typeof ApiPlaylistIdRoute
'/_api/series/$id': typeof ApiSeriesIdRoute
'/setup/server/add': typeof SetupServerAddRoute
'/setup/server/error': typeof SetupServerErrorRoute
'/setup/server/list': typeof SetupServerListRoute
'/_api/favorite/': typeof ApiFavoriteIndexRoute
'/_api/home/': typeof ApiHomeIndexRoute
'/_api/player/': typeof ApiPlayerIndexRoute
'/_api/search/': typeof ApiSearchIndexRoute
'/_api/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute
}
interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath
fullPaths:
| '/'
| ''
| '/library'
| '/login'
| '/search'
| '/error/$code'
| '/album/$id'
| '/artist/$id'
| '/boxset/$id'
| '/episode/$id'
| '/item/$id'
| '/library/$id'
| '/login/list'
| '/login/manual'
| '/person/$id'
| '/player/audio'
| '/playlist/$id'
| '/series/$id'
| '/setup/server/add'
| '/setup/server/error'
| '/setup/server/list'
| '/favorite'
| '/home'
| '/player'
| '/search/'
| '/login/$userId/$userName'
fileRoutesByTo: FileRoutesByTo
to:
| '/'
| ''
| '/library'
| '/login'
| '/error/$code'
| '/album/$id'
| '/artist/$id'
| '/boxset/$id'
| '/episode/$id'
| '/item/$id'
| '/library/$id'
| '/login/list'
| '/login/manual'
| '/person/$id'
| '/player/audio'
| '/playlist/$id'
| '/series/$id'
| '/setup/server/add'
| '/setup/server/error'
| '/setup/server/list'
| '/favorite'
| '/home'
| '/player'
| '/search'
| '/login/$userId/$userName'
id:
| '/'
| '/_api'
| '/_api/library'
| '/_api/login'
| '/_api/search'
| '/error/$code'
| '/_api/album/$id'
| '/_api/artist/$id'
| '/_api/boxset/$id'
| '/_api/episode/$id'
| '/_api/item/$id'
| '/_api/library/$id'
| '/_api/login/list'
| '/_api/login/manual'
| '/_api/person/$id'
| '/_api/player/audio'
| '/_api/playlist/$id'
| '/_api/series/$id'
| '/setup/server/add'
| '/setup/server/error'
| '/setup/server/list'
| '/_api/favorite/'
| '/_api/home/'
| '/_api/player/'
| '/_api/search/'
| '/_api/login/$userId/$userName'
fileRoutesById: FileRoutesById
}
interface RootRouteChildren {
IndexRoute: typeof IndexRoute
ApiRoute: typeof ApiRouteWithChildren
ErrorCodeRoute: typeof ErrorCodeRoute
SetupServerAddRoute: typeof SetupServerAddRoute
SetupServerErrorRoute: typeof SetupServerErrorRoute
SetupServerListRoute: typeof SetupServerListRoute
}
const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
ApiRoute: ApiRouteWithChildren,
ErrorCodeRoute: ErrorCodeRoute,
SetupServerAddRoute: SetupServerAddRoute,
SetupServerErrorRoute: SetupServerErrorRoute,
SetupServerListRoute: SetupServerListRoute,
}
export const routeTree = rootRoute
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()
/* prettier-ignore-end */ /* prettier-ignore-end */
+159 -97
View File
@@ -1,5 +1,5 @@
import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow"; import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
import React, { MouseEventHandler, type ChangeEventHandler } from "react"; import React from "react";
import { useLayoutEffect, useMemo } from "react"; import { useLayoutEffect, useMemo } from "react";
import CircularProgress from "@mui/material/CircularProgress"; import CircularProgress from "@mui/material/CircularProgress";
@@ -35,9 +35,11 @@ import { AnimatePresence, motion } from "framer-motion";
import { setBackdrop } from "@/utils/store/backdrop"; import { setBackdrop } from "@/utils/store/backdrop";
import { Button, TextField } from "@mui/material"; import { Button, LinearProgress, TextField } from "@mui/material";
import JASSUB from "jassub"; import JASSUB from "jassub";
//@ts-ignore
import workerUrl from "jassub/dist/jassub-worker.js?url"; import workerUrl from "jassub/dist/jassub-worker.js?url";
//@ts-ignore
import wasmUrl from "jassub/dist/jassub-worker.wasm?url"; import wasmUrl from "jassub/dist/jassub-worker.wasm?url";
import PlayNextButton from "@/components/buttons/playNextButton"; import PlayNextButton from "@/components/buttons/playNextButton";
@@ -46,11 +48,9 @@ import QueueButton from "@/components/buttons/queueButton";
import OutroCard from "@/components/outroCard"; import OutroCard from "@/components/outroCard";
import { useApiInContext } from "@/utils/store/api"; import { useApiInContext } from "@/utils/store/api";
import useQueue from "@/utils/store/queue"; import useQueue from "@/utils/store/queue";
import type { Mark } from "@mui/material/Slider/useSlider.types";
import { createFileRoute, useRouter } from "@tanstack/react-router"; import { createFileRoute, useRouter } from "@tanstack/react-router";
import axios from "axios"; import { toNumber } from "lodash";
import type { OnProgressProps } from "react-player/base"; import type { OnProgressProps } from "react-player/base";
import subtitleFont from "./Noto-Sans-Indosphere.ttf";
const ticksDisplay = (ticks: number) => { const ticksDisplay = (ticks: number) => {
const time = Math.round(ticks / 10000); const time = Math.round(ticks / 10000);
@@ -73,7 +73,7 @@ const ticksDisplay = (ticks: number) => {
})}`; })}`;
return formatedTime; return formatedTime;
}; };
const VOLUME_SCROLL_INTERVAL = 0.05; const VOLUME_SCROLL_INTERVAL = 0.02;
export const Route = createFileRoute("/_api/player/")({ export const Route = createFileRoute("/_api/player/")({
component: VideoPlayer, component: VideoPlayer,
@@ -113,7 +113,9 @@ function VideoPlayer() {
]); ]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [settingsMenu, setSettingsMenu] = useState(null); const [settingsMenu, setSettingsMenu] = useState<HTMLButtonElement | null>(
null,
);
const settingsMenuOpen = Boolean(settingsMenu); const settingsMenuOpen = Boolean(settingsMenu);
const [showVolumeControl, setShowVolumeControl] = useState(false); const [showVolumeControl, setShowVolumeControl] = useState(false);
@@ -130,18 +132,12 @@ function VideoPlayer() {
useEffect(() => setBackdrop("", ""), []); useEffect(() => setBackdrop("", ""), []);
const [clickTimeout, setClickTimeout] = useState<NodeJS.Timeout>(null); const [clickTimeout, setClickTimeout] = useState<NodeJS.Timeout>(null!);
const showSubtitles = useMemo(
() => mediaSource.subtitle.enable,
[mediaSource.subtitle],
);
const handleReady = async () => { const handleReady = async () => {
if (!isReady) { if (!isReady) {
player.current?.seekTo(ticksToSec(startPosition), "seconds"); player.current?.seekTo(ticksToSec(startPosition), "seconds");
setIsReady(true); setIsReady(true);
console.log(item);
// Report Jellyfin server: Playback has begin // Report Jellyfin server: Playback has begin
getPlaystateApi(api).reportPlaybackStart({ getPlaystateApi(api).reportPlaybackStart({
playbackStartInfo: { playbackStartInfo: {
@@ -212,41 +208,43 @@ function VideoPlayer() {
timer = setTimeout(() => setHoveringOsd(false), 5000); timer = setTimeout(() => setHoveringOsd(false), 5000);
}; };
const handleKeyPress = useCallback((event) => { const handleKeyPress = useCallback((event: KeyboardEvent) => {
switch (event.key) { if (player.current) {
case "ArrowRight": switch (event.key) {
player.current.seekTo(player.current.getCurrentTime() + 10); case "ArrowRight":
break; player.current.seekTo(player.current.getCurrentTime() + 10);
case "ArrowLeft": break;
player.current.seekTo(player.current.getCurrentTime() - 10); case "ArrowLeft":
break; player.current.seekTo(player.current.getCurrentTime() - 10);
case " ": break;
setPlaying((state) => !state); case " ":
break; setPlaying((state) => !state);
case "ArrowUp": break;
// setVolume((state) => (state <= 0.9 ? state + 0.1 : state)); case "ArrowUp":
break; // setVolume((state) => (state <= 0.9 ? state + 0.1 : state));
case "ArrowDown": break;
// setVolume((state) => (state >= 0.1 ? state - 0.1 : state)); case "ArrowDown":
break; // setVolume((state) => (state >= 0.1 ? state - 0.1 : state));
case "F": break;
case "f": case "F":
setAppFullscreen((state) => { case "f":
appWindow.getCurrent().setFullscreen(!state); setAppFullscreen((state) => {
return !state; appWindow.getCurrent().setFullscreen(!state);
}); return !state;
break; });
case "P": break;
case "p": case "P":
// setIsPIP((state) => !state); case "p":
break; // setIsPIP((state) => !state);
case "M": break;
case "m": case "M":
// setIsMuted((state) => !state); case "m":
break; // setIsMuted((state) => !state);
default: break;
console.log(event.key); default:
break; console.log(event.key);
break;
}
} }
}, []); }, []);
@@ -262,8 +260,6 @@ function VideoPlayer() {
useEffect(() => { useEffect(() => {
const handleMouseWheel = (event: WheelEvent) => { const handleMouseWheel = (event: WheelEvent) => {
console.log(event.deltaY);
if (event.deltaY < 0) { if (event.deltaY < 0) {
// increase volume // increase volume
setVolume((state) => Math.min(1, state + VOLUME_SCROLL_INTERVAL)); setVolume((state) => Math.min(1, state + VOLUME_SCROLL_INTERVAL));
@@ -305,11 +301,6 @@ function VideoPlayer() {
} }
return []; return [];
}, [mediaSource.subtitle.track, mediaSource.subtitle.enable]); }, [mediaSource.subtitle.track, mediaSource.subtitle.enable]);
const handleSubtitleChange = (
e: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>,
) => {
changeSubtitleTrack(e.target.value, mediaSource.subtitle.allTracks);
};
useEffect(() => { useEffect(() => {
if (player.current?.getInternalPlayer() && mediaSource.subtitle.enable) { if (player.current?.getInternalPlayer() && mediaSource.subtitle.enable) {
@@ -318,6 +309,7 @@ function VideoPlayer() {
mediaSource.subtitle.format === "ssa" mediaSource.subtitle.format === "ssa"
) { ) {
const jassubRenderer = new JASSUB({ const jassubRenderer = new JASSUB({
//@ts-ignore
video: player.current?.getInternalPlayer(), video: player.current?.getInternalPlayer(),
workerUrl, workerUrl,
wasmUrl, wasmUrl,
@@ -375,11 +367,10 @@ function VideoPlayer() {
useEffect(() => setForceShowCredits(false), [item?.Id]); useEffect(() => setForceShowCredits(false), [item?.Id]);
const chapterMarks = useMemo(() => { const chapterMarks = useMemo(() => {
const marks: Mark[] = []; const marks: { value: number }[] = [];
item?.Chapters?.map((val) => { item?.Chapters?.map((val) => {
marks.push({ value: val.StartPositionTicks ?? 0 }); marks.push({ value: val.StartPositionTicks ?? 0 });
}); });
console.log(item);
return marks; return marks;
}, [item?.Chapters]); }, [item?.Chapters]);
@@ -390,15 +381,19 @@ function VideoPlayer() {
} }
if (isSeeking) { if (isSeeking) {
if ( if (
item.Chapters?.[index + 1]?.StartPositionTicks - sliderProgress > 0 && (item.Chapters?.[index + 1]?.StartPositionTicks ?? sliderProgress) -
chapter.StartPositionTicks - sliderProgress < 0 sliderProgress >=
0 &&
(chapter.StartPositionTicks ?? sliderProgress) - sliderProgress < 0
) { ) {
return chapter; return chapter;
} }
} else { } else {
if ( if (
item.Chapters?.[index + 1]?.StartPositionTicks - progress > 0 && (item.Chapters?.[index + 1]?.StartPositionTicks ?? progress) -
chapter.StartPositionTicks - progress < 0 progress >=
0 &&
(chapter.StartPositionTicks ?? progress) - progress < 0
) { ) {
return chapter; return chapter;
} }
@@ -415,8 +410,9 @@ function VideoPlayer() {
for (const [_, trickInfo] of Object.entries(trickplayResolutions)) { for (const [_, trickInfo] of Object.entries(trickplayResolutions)) {
if ( if (
!bestWidth || !bestWidth ||
(trickInfo.Width < bestWidth && bestWidth > maxWidth) || (trickInfo.Width &&
(trickInfo.Width > bestWidth && bestWidth <= maxWidth) ((trickInfo.Width < bestWidth && bestWidth > maxWidth) ||
(trickInfo.Width > bestWidth && bestWidth <= maxWidth)))
) { ) {
bestWidth = trickInfo.Width; bestWidth = trickInfo.Width;
} }
@@ -435,28 +431,49 @@ function VideoPlayer() {
? Math.floor(ticksToMs(value) / trickplayResolution?.Interval) ? Math.floor(ticksToMs(value) / trickplayResolution?.Interval)
: 0; : 0;
const trickplayImageSize = const trickplayImageSize =
trickplayResolution?.TileWidth * trickplayResolution?.TileHeight; trickplayResolution?.TileWidth * trickplayResolution?.TileHeight; // this gives the area of a single tile
const trickplayImageOffset = currentTrickplayImage % trickplayImageSize; const trickplayImageOffset = currentTrickplayImage % trickplayImageSize; // this gives the tile index inside a trickplay image
console.log(trickplayImageOffset); const index = Math.floor(currentTrickplayImage / trickplayImageSize); // this gives the index of trickplay image
const index = Math.floor(currentTrickplayImage / trickplayImageSize);
const imageOffsetX = const imageOffsetX =
trickplayImageOffset % trickplayResolution?.TileWidth; trickplayImageOffset % trickplayResolution?.TileWidth; // this gives the x coordinate of tile in trickplay image
const imageOffsetY = Math.floor( const imageOffsetY = Math.floor(
trickplayImageOffset / trickplayResolution?.TileWidth, trickplayImageOffset / trickplayResolution?.TileWidth,
); ); // this gives the y coordinate of tile in trickplay image
const backgroundOffsetX = -(imageOffsetX * trickplayResolution?.Width); const backgroundOffsetX = -(imageOffsetX * trickplayResolution?.Width);
const backgroundOffsetY = -(imageOffsetY * trickplayResolution?.Height); const backgroundOffsetY = -(imageOffsetY * trickplayResolution?.Height);
const imgUrlParamsObject = { const imgUrlParamsObject: Record<string, string> = {
api_key: api.accessToken, api_key: api.accessToken,
MediaSourceId: mediaSource.id, MediaSourceId: mediaSource.id ?? "",
}; };
const imgUrlParams = new URLSearchParams(imgUrlParamsObject); const imgUrlParams = new URLSearchParams(imgUrlParamsObject).toString();
if (currentChapter?.[0]?.Name) {
return (
<div className="flex flex-column video-osb-bubble glass">
<div
className="video-osd-trickplayBubble"
style={{
background: `url(${api.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
backgroundPositionX: `${backgroundOffsetX}px`,
backgroundPositionY: `${backgroundOffsetY}px`,
width: `${trickplayResolution.Width}px`,
height: `${trickplayResolution.Height}px`,
}}
/>
<Typography variant="h6" px={2} pt={1}>
{currentChapter?.[0]?.Name}
</Typography>
<Typography px={2} pb={1}>
{ticksDisplay(value)}
</Typography>
</div>
);
}
return ( return (
<div className="flex flex-column"> <div className="flex flex-column video-osb-bubble glass">
<div <div
className="video-osd-trickplayBubble" className="video-osd-trickplayBubble"
style={{ style={{
@@ -464,31 +481,44 @@ function VideoPlayer() {
backgroundPositionX: `${backgroundOffsetX}px`, backgroundPositionX: `${backgroundOffsetX}px`,
backgroundPositionY: `${backgroundOffsetY}px`, backgroundPositionY: `${backgroundOffsetY}px`,
width: `${trickplayResolution.Width}px`, width: `${trickplayResolution.Width}px`,
height: `${trickplayResolution.Height}px`,
}} }}
/> />
<Typography>{currentChapter?.[0].Name}</Typography> <Typography variant="h6" px={2} py={1}>
<Typography>{ticksDisplay(value)}</Typography> {ticksDisplay(value)}
</Typography>
</div>
);
}
if (currentChapter?.[0]?.Name) {
return (
<div className="flex flex-column video-osb-bubble glass">
<Typography variant="h6" px={2} pt={1}>
{currentChapter?.[0]?.Name}
</Typography>
<Typography px={2} pb={1}>
{ticksDisplay(value)}
</Typography>
</div> </div>
); );
} }
return ( return (
<div className="flex flex-column"> <div className="flex flex-column video-osb-bubble glass">
<Typography>{currentChapter?.[0].Name}</Typography> <Typography variant="h6" px={2} py={1}>
<Typography>{ticksDisplay(value)}</Typography> {ticksDisplay(value)}
</Typography>
</div> </div>
); );
}; };
// useEffect(() => { const [showVolumeIndicator, setVolumeIndicator] = useState(false);
// async function testTrick() { useEffect(() => {
// const result = await axios.get( setVolumeIndicator(true);
// `${api.basePath}/Videos/${item?.Id}/Trickplay/320/0.jpg`, const timeout = setTimeout(() => {
// { headers: { Authorization: api.authorizationHeader } }, setVolumeIndicator(false);
// ); }, 1000);
// console.log(result); return () => clearTimeout(timeout);
// } }, [volume]);
// testTrick();
// }, []);
return ( return (
<div className="video-player"> <div className="video-player">
@@ -520,6 +550,7 @@ function VideoPlayer() {
<Button <Button
variant="outlined" variant="outlined"
size="large" size="large"
//@ts-ignore
color="white" color="white"
style={{ style={{
position: "absolute", position: "absolute",
@@ -535,6 +566,25 @@ function VideoPlayer() {
{!forceShowCredits && showUpNextCard && ( {!forceShowCredits && showUpNextCard && (
<OutroCard handleShowCredits={handleShowCredits} /> <OutroCard handleShowCredits={handleShowCredits} />
)} )}
<AnimatePresence>
{showVolumeIndicator && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="video-volume-indicator glass"
>
<div className="material-symbols-rounded">
{volume > 0.7 ? "volume_up" : "volume_down"}
</div>
<LinearProgress
style={{ width: "100%" }}
value={volume * 100}
variant="determinate"
/>
</motion.div>
)}
</AnimatePresence>
<motion.div <motion.div
className={ className={
hoveringOsd || !playing || isSeeking hoveringOsd || !playing || isSeeking
@@ -575,9 +625,7 @@ function VideoPlayer() {
<IconButton onClick={handleExitPlayer}> <IconButton onClick={handleExitPlayer}>
<span className="material-symbols-rounded">arrow_back</span> <span className="material-symbols-rounded">arrow_back</span>
</IconButton> </IconButton>
<IconButton <IconButton onClick={(e) => setSettingsMenu(e.currentTarget)}>
onClick={(e: MouseEvent) => setSettingsMenu(e.currentTarget)}
>
<span className="material-symbols-rounded">settings</span> <span className="material-symbols-rounded">settings</span>
</IconButton> </IconButton>
<Menu <Menu
@@ -606,7 +654,14 @@ function VideoPlayer() {
label="Subtitles" label="Subtitles"
variant="outlined" variant="outlined"
value={mediaSource.subtitle.track} value={mediaSource.subtitle.track}
onChange={handleSubtitleChange} onChange={(e) => {
if (mediaSource.subtitle.allTracks) {
changeSubtitleTrack(
toNumber(e.target.value),
mediaSource.subtitle.allTracks,
);
}
}}
fullWidth fullWidth
disabled={mediaSource.subtitle.track === -2} disabled={mediaSource.subtitle.track === -2}
> >
@@ -624,10 +679,10 @@ function VideoPlayer() {
{(forceShowCredits || !showUpNextCard) && ( {(forceShowCredits || !showUpNextCard) && (
<div className="video-player-osd-info"> <div className="video-player-osd-info">
<Typography variant="h4" fontWeight={500} mb={2}> <Typography variant="h4" fontWeight={500} mb={2}>
<>{itemName}</> {itemName}
{episodeTitle && ( {episodeTitle && (
<Typography variant="h6" fontWeight={300} mt={1}> <Typography variant="h6" fontWeight={300} mt={1}>
<>{episodeTitle}</> {episodeTitle}
</Typography> </Typography>
)} )}
</Typography> </Typography>
@@ -636,7 +691,7 @@ function VideoPlayer() {
<Slider <Slider
value={isSeeking ? sliderProgress : progress} value={isSeeking ? sliderProgress : progress}
max={itemDuration} max={itemDuration}
step={secToTicks(10)} step={1}
onChange={(_, newValue) => { onChange={(_, newValue) => {
setIsSeeking(true); setIsSeeking(true);
Array.isArray(newValue) Array.isArray(newValue)
@@ -648,7 +703,14 @@ function VideoPlayer() {
Array.isArray(newValue) Array.isArray(newValue)
? setProgress(newValue[0]) ? setProgress(newValue[0])
: setProgress(newValue); : setProgress(newValue);
player.current?.seekTo(ticksToSec(newValue), "seconds"); if (Array.isArray(newValue)) {
player.current?.seekTo(
ticksToSec(newValue[0]),
"seconds",
);
} else {
player.current?.seekTo(ticksToSec(newValue), "seconds");
}
}} }}
sx={{ sx={{
"& .MuiSlider-thumb": { "& .MuiSlider-thumb": {
+30
View File
@@ -18,6 +18,10 @@
} }
gap: 0.5em; gap: 0.5em;
} }
&-trick-bubble{
overflow: hidden;
border-radius: $border-radius-default;
}
} }
&-osd-visible { &-osd-visible {
cursor: default; cursor: default;
@@ -32,6 +36,25 @@
bottom: 0; bottom: 0;
overflow: hidden; overflow: hidden;
} }
&-volume-indicator{
display: flex;
flex-direction: column;
width: 12em;
aspect-ratio: 1;
padding: 2em;
align-items: center;
justify-content: center;
gap: 1.5em;
position: fixed;
top: 5em;
right: 2em;
z-index: 10;
border-radius: 2em;
.material-symbols-rounded{
font-size: 3em;
--fill:1;
}
}
} }
video { video {
@@ -90,5 +113,12 @@ video {
align-items: center; align-items: center;
} }
} }
.MuiSlider-valueLabel {
padding: 0;
background: transparent;
overflow: hidden;
border-radius: $border-radius-default;
border: 1.2px solid rgb(255 255 255 / 0.1);
}
} }
} }