feat: add subtitle support #337
This commit is contained in:
20 files changed
+4958
-4755
No files matched your search
@@ -1,5 +1,5 @@
|
||||
.audio {
|
||||
&-hidden{
|
||||
&-hidden {
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
&-info {
|
||||
@@ -43,29 +43,68 @@
|
||||
gap: 1em;
|
||||
}
|
||||
}
|
||||
&-queue{
|
||||
&-queue {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
gap: 1em;
|
||||
margin-top: 2em;
|
||||
&-track{
|
||||
&-track {
|
||||
display: grid;
|
||||
grid-template-columns: 3em 1fr 6em;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
gap: 1em;
|
||||
&-info-name{
|
||||
&-info-name {
|
||||
transition: $transition-time-fast;
|
||||
}
|
||||
&.active{
|
||||
.audio-queue-track-info-name{
|
||||
&.active {
|
||||
.audio-queue-track-info-name {
|
||||
color: $clr-accent-default;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
&-lyrics {
|
||||
max-height: 40vh;
|
||||
overflow:visible;
|
||||
background: rgb(255 255 255 / 0.05);
|
||||
// border: 1px solid rgb(255 255 255 / 0.2);
|
||||
padding: 2em;
|
||||
position: relative;
|
||||
margin-bottom: 2em;
|
||||
border-radius: 20px;
|
||||
&-line {
|
||||
width: fit-content;
|
||||
white-space: wrap;
|
||||
text-align: center;
|
||||
font-size: 1.5em;
|
||||
opacity: 0.5;
|
||||
transform: scale(1);
|
||||
transition: transform $transition-time-default;
|
||||
&[data-active-lyric="true"] {
|
||||
opacity: 1;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
}
|
||||
&[data-has-synced-lyrics="false"] {
|
||||
.audio-lyrics-line {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
&-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: scroll;
|
||||
height: calc(40vh - 4em);
|
||||
width: 100%;
|
||||
overflow-x: visible !important;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
top: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,13 @@ import { useAudioPlayback } from "@/utils/store/audioPlayback";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import { Fab, IconButton, Slider, Typography } from "@mui/material";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
import "./audio.scss";
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
@@ -24,8 +30,10 @@ function AudioPlayerRoute() {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const [queue, currentTrack] = useQueue((s) => [s.tracks, s.currentItemIndex]);
|
||||
const [item] = useAudioPlayback((s) => [s.item]);
|
||||
const audioPlayer: HTMLAudioElement | null =
|
||||
document.querySelector("#audio-player");
|
||||
const audioPlayer: HTMLAudioElement | null = useMemo(
|
||||
() => document.querySelector("#audio-player"),
|
||||
[item],
|
||||
);
|
||||
|
||||
const [isScrubbing, setIsScrubbing] = useState(false);
|
||||
const [sliderProgress, setSliderProgress] = useState<number | number[]>(0); // this state hold the slider scrubbing value allowing user to scrub track without changing current time
|
||||
@@ -33,23 +41,44 @@ function AudioPlayerRoute() {
|
||||
audioPlayer?.currentTime ?? 0,
|
||||
);
|
||||
|
||||
const [showLyrics, setShowLyrics] = useState(false);
|
||||
|
||||
const lyrics = useQuery({
|
||||
queryKey: ["player", "audio", item?.Id, "lyrics"],
|
||||
queryFn: async () =>
|
||||
await getLyricsApi(api).getLyrics({
|
||||
itemId: item?.Id,
|
||||
}),
|
||||
(
|
||||
await getLyricsApi(api).searchRemoteLyrics({
|
||||
itemId: item?.Id,
|
||||
})
|
||||
).data,
|
||||
enabled: Boolean(item?.Id),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
audioPlayer?.addEventListener("timeupdate", () => {
|
||||
setProgress(audioPlayer.currentTime);
|
||||
setProgress(audioPlayer.currentTime ?? 0);
|
||||
});
|
||||
}, [item?.Id]);
|
||||
console.log(audioPlayer);
|
||||
}, [item?.Id, currentTrack]);
|
||||
|
||||
const lyricsContainer = useRef<HTMLDivElement | null>(null);
|
||||
useEffect(() => {
|
||||
if (showLyrics) {
|
||||
const currentLyric = document.querySelector("[data-active-lyric='true']");
|
||||
currentLyric?.scrollIntoView({
|
||||
block: "nearest",
|
||||
inline: "nearest",
|
||||
behavior: "smooth",
|
||||
});
|
||||
}
|
||||
}, [showLyrics, audioPlayer?.currentTime]);
|
||||
|
||||
return (
|
||||
<div className="scrollY padded-top flex flex-column" style={{ gap: "1em" }}>
|
||||
<div
|
||||
className="scrollY padded-top flex flex-column"
|
||||
style={{ gap: "1em" }}
|
||||
key={queue[currentTrack]?.Id}
|
||||
>
|
||||
<div className="audio-info-container">
|
||||
<div className="audio-info-image-container">
|
||||
{item?.ImageTags?.Primary ? (
|
||||
@@ -77,84 +106,152 @@ function AudioPlayerRoute() {
|
||||
>
|
||||
by {item?.Artists?.join(", ")}
|
||||
</Typography>
|
||||
<Slider
|
||||
style={{
|
||||
marginTop: "1.2em",
|
||||
}}
|
||||
value={isScrubbing ? sliderProgress : secToTicks(progress)}
|
||||
max={item?.RunTimeTicks ?? 1}
|
||||
step={1}
|
||||
onChange={(_, newVal) => {
|
||||
setIsScrubbing(true);
|
||||
setSliderProgress(newVal);
|
||||
}}
|
||||
onChangeCommitted={(_, newVal) => {
|
||||
setIsScrubbing(false);
|
||||
Array.isArray(newVal)
|
||||
? setProgress(ticksToSec(newVal[0]))
|
||||
: setProgress(ticksToSec(newVal));
|
||||
audioPlayer?.currentTime = Array.isArray(newVal)
|
||||
? ticksToSec(newVal[0])
|
||||
: ticksToSec(newVal);
|
||||
}}
|
||||
sx={{
|
||||
"& .MuiSlider-thumb": {
|
||||
width: 14,
|
||||
height: 14,
|
||||
transition: "0.1s ease-in-out",
|
||||
opacity: 0,
|
||||
"&.Mui-active": {
|
||||
width: 20,
|
||||
height: 20,
|
||||
<div
|
||||
className="flex flex-row"
|
||||
style={{ gap: "1em", alignItems: "center" }}
|
||||
>
|
||||
<Typography variant="subtitle2" className="opacity-07">
|
||||
{getRuntimeMusic(secToTicks(audioPlayer?.currentTime) ?? 0)}
|
||||
</Typography>
|
||||
<Slider
|
||||
value={isScrubbing ? sliderProgress : secToTicks(progress)}
|
||||
max={item?.RunTimeTicks ?? 1}
|
||||
step={1}
|
||||
onChange={(_, newVal) => {
|
||||
setIsScrubbing(true);
|
||||
setSliderProgress(newVal);
|
||||
}}
|
||||
onChangeCommitted={(_, newVal) => {
|
||||
setIsScrubbing(false);
|
||||
Array.isArray(newVal)
|
||||
? setProgress(ticksToSec(newVal[0]))
|
||||
: setProgress(ticksToSec(newVal));
|
||||
audioPlayer?.currentTime = Array.isArray(newVal)
|
||||
? ticksToSec(newVal[0])
|
||||
: ticksToSec(newVal);
|
||||
}}
|
||||
sx={{
|
||||
"& .MuiSlider-thumb": {
|
||||
width: 14,
|
||||
height: 14,
|
||||
transition: "0.1s ease-in-out",
|
||||
opacity: 0,
|
||||
"&.Mui-active": {
|
||||
width: 20,
|
||||
height: 20,
|
||||
opacity: 1,
|
||||
},
|
||||
},
|
||||
"&:hover .MuiSlider-thumb": {
|
||||
opacity: 1,
|
||||
},
|
||||
},
|
||||
"&:hover .MuiSlider-thumb": {
|
||||
opacity: 1,
|
||||
},
|
||||
"& .MuiSlider-rail": {
|
||||
opacity: 0.28,
|
||||
background: "white",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<div className="audio-info-controls">
|
||||
<PlayPreviousButton />
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
audioPlayer?.currentTime -= SEEK_AMOUNT;
|
||||
"& .MuiSlider-rail": {
|
||||
opacity: 0.28,
|
||||
background: "white",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded">fast_rewind</span>
|
||||
</IconButton>
|
||||
<Fab
|
||||
disabled={!audioPlayer?.readyState}
|
||||
color="white"
|
||||
size="large"
|
||||
onClick={() =>
|
||||
audioPlayer?.paused ? audioPlayer.play() : audioPlayer?.pause()
|
||||
}
|
||||
>
|
||||
<span
|
||||
className="fill material-symbols-rounded"
|
||||
style={{
|
||||
fontSize: "2.4em",
|
||||
/>
|
||||
<Typography variant="subtitle2" className="opacity-07">
|
||||
{getRuntimeMusic(item?.RunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<div className="audio-info-controls">
|
||||
<PlayPreviousButton />
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
audioPlayer?.currentTime -= SEEK_AMOUNT;
|
||||
}}
|
||||
>
|
||||
{audioPlayer?.paused ? "play_arrow" : "pause"}
|
||||
<span className="material-symbols-rounded">fast_rewind</span>
|
||||
</IconButton>
|
||||
<Fab
|
||||
disabled={!audioPlayer?.readyState}
|
||||
color="white"
|
||||
size="large"
|
||||
onClick={() =>
|
||||
audioPlayer?.paused
|
||||
? audioPlayer.play()
|
||||
: audioPlayer?.pause()
|
||||
}
|
||||
>
|
||||
<span
|
||||
className="fill material-symbols-rounded"
|
||||
style={{
|
||||
fontSize: "2.4em",
|
||||
}}
|
||||
>
|
||||
{audioPlayer?.paused ? "play_arrow" : "pause"}
|
||||
</span>
|
||||
</Fab>
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
audioPlayer?.currentTime += SEEK_AMOUNT;
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded">fast_forward</span>
|
||||
</IconButton>
|
||||
<PlayNextButton />
|
||||
</div>
|
||||
<IconButton onClick={() => setShowLyrics((s) => !s)}>
|
||||
<span
|
||||
className={
|
||||
showLyrics
|
||||
? "material-symbols-rounded fill"
|
||||
: "material-symbols-rounded"
|
||||
}
|
||||
>
|
||||
lyrics
|
||||
</span>
|
||||
</Fab>
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
audioPlayer?.currentTime += SEEK_AMOUNT;
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded">fast_forward</span>
|
||||
</IconButton>
|
||||
<PlayNextButton />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{showLyrics && (
|
||||
<div
|
||||
className="audio-lyrics"
|
||||
data-has-synced-lyrics={Boolean(
|
||||
lyrics.data?.[0]?.Lyrics?.Metadata?.IsSynced,
|
||||
)}
|
||||
>
|
||||
<div className="audio-lyrics-container" ref={lyricsContainer}>
|
||||
{lyrics.data?.[1]?.Lyrics?.Lyrics?.map((lyric, index) => (
|
||||
<div
|
||||
className="audio-lyrics-line"
|
||||
key={`${lyric.Text}${index}`}
|
||||
data-active-lyric={
|
||||
secToTicks(audioPlayer?.currentTime) >= lyric.Start &&
|
||||
secToTicks(audioPlayer?.currentTime) <
|
||||
(lyrics.data?.[0]?.Lyrics?.Lyrics?.[index + 1]?.Start ?? 0)
|
||||
}
|
||||
>
|
||||
{lyric.Text}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{!lyrics.data?.[0]?.Lyrics?.Metadata?.IsSynced && (
|
||||
<Typography
|
||||
className="flex flex-align-center"
|
||||
style={{
|
||||
position: "absolute",
|
||||
bottom: "-2em",
|
||||
opacity: 0.7,
|
||||
gap: "0.4em",
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded">info</span>
|
||||
Synced subtitles no available
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="audio-queue-container">
|
||||
<Typography variant="h5">Queue:</Typography>
|
||||
<div className="audio-queue">
|
||||
|
||||
@@ -40,6 +40,7 @@ import PlayNextButton from "@/components/buttons/playNextButton";
|
||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||
import QueueButton from "@/components/buttons/queueButton";
|
||||
import OutroCard from "@/components/outroCard";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
||||
import type { OnProgressProps } from "react-player/base";
|
||||
import subtitleFont from "./Noto-Sans-Indosphere.ttf";
|
||||
@@ -98,6 +99,10 @@ function VideoPlayer() {
|
||||
state.playsessionId,
|
||||
state.intro,
|
||||
]);
|
||||
const [currentQueueItemIndex, queue] = useQueue((s) => [
|
||||
s.currentItemIndex,
|
||||
s.tracks,
|
||||
]);
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [settingsMenu, setSettingsMenu] = useState(null);
|
||||
@@ -330,6 +335,9 @@ function VideoPlayer() {
|
||||
}, [progress]);
|
||||
|
||||
const showUpNextCard = useMemo(() => {
|
||||
if (queue[currentQueueItemIndex]?.Id === queue[queue.length - 1]?.Id) {
|
||||
return false; // Check if the current playing episode is last episode in queue
|
||||
}
|
||||
if (introInfo?.Credits) {
|
||||
if (
|
||||
ticksToSec(progress) >= introInfo?.Credits.ShowSkipPromptAt &&
|
||||
|
||||
Reference in new issue
Block a user