fix: audio player not playing audio
This commit is contained in:
14 files changed
+630
-633
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 103 KiB |
@@ -1,3 +1,3 @@
|
||||
<svg width="1310" height="1512" viewBox="0 0 1310 1512" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M654.715 756L52 1103.98L654.715 1451.96L1257.43 1103.98V408.022L654.715 60.0444L52 408.022L654.715 756ZM654.715 0L1309.43 378V1134L654.715 1512L0 1134V1073.96V438.044V378L654.715 0Z" fill="#101010"/>
|
||||
<svg width="1512" height="1512" viewBox="0 0 1512 1512" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M755.715 756L153 1103.98L755.715 1451.96L1358.43 1103.98V408.022L755.715 60.0444L153 408.022L755.715 756ZM755.715 0L1410.43 378V1134L755.715 1512L101 1134V1073.96V438.044V378L755.715 0Z" fill="white"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 360 B After Width: | Height: | Size: 362 B |
@@ -9,7 +9,7 @@ import Fab from "@mui/material/Fab";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import { playAudio } from "@/utils/store/audioPlayback";
|
||||
import { generateAudioStreamUrl, playAudio } from "@/utils/store/audioPlayback";
|
||||
import {
|
||||
type BaseItemDto,
|
||||
type BaseItemDtoQueryResult,
|
||||
@@ -50,22 +50,28 @@ import type { AxiosResponse } from "axios";
|
||||
|
||||
type PlayButtonProps = {
|
||||
item: BaseItemDto;
|
||||
itemId: string;
|
||||
itemUserData: UserItemDataDto;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
itemId?: string;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
itemUserData?: UserItemDataDto;
|
||||
userId: string | undefined;
|
||||
itemType: BaseItemKind;
|
||||
currentAudioTrack: number;
|
||||
currentVideoTrack: number;
|
||||
currentSubTrack: number | "nosub";
|
||||
className: string;
|
||||
sx: SxProps;
|
||||
buttonProps: ButtonProps;
|
||||
iconOnly: boolean;
|
||||
audio: boolean;
|
||||
size: ButtonPropsSizeOverrides;
|
||||
playlistItem: BaseItemDto;
|
||||
playlistItemId: string;
|
||||
trackIndex: number;
|
||||
currentAudioTrack?: number;
|
||||
currentVideoTrack?: number;
|
||||
currentSubTrack?: number | "nosub";
|
||||
className?: string;
|
||||
sx?: SxProps;
|
||||
buttonProps?: ButtonProps;
|
||||
iconOnly?: boolean;
|
||||
audio?: boolean;
|
||||
size?: ButtonPropsSizeOverrides;
|
||||
playlistItem?: BaseItemDto;
|
||||
playlistItemId?: string;
|
||||
trackIndex?: number;
|
||||
};
|
||||
|
||||
// Memoized LinearProgress component
|
||||
@@ -119,7 +125,7 @@ const PlayButton = ({
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const itemQuery = useMutation({
|
||||
mutationKey: ["playButton", itemId, userId],
|
||||
mutationKey: ["playButton", item?.Id, userId],
|
||||
mutationFn: async () => {
|
||||
setPlaybackDataLoading(true);
|
||||
let result: undefined | AxiosResponse<BaseItemDtoQueryResult, any>;
|
||||
@@ -182,7 +188,7 @@ const PlayButton = ({
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
result = await getTvShowsApi(api).getEpisodes({
|
||||
seriesId: itemId,
|
||||
seriesId: item.Id,
|
||||
fields: [
|
||||
ItemFields.MediaSources,
|
||||
ItemFields.MediaStreams,
|
||||
@@ -233,7 +239,7 @@ const PlayButton = ({
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
result = await getItemsApi(api).getItems({
|
||||
parentId: itemId,
|
||||
parentId: item.Id,
|
||||
userId: userId,
|
||||
fields: [ItemFields.MediaSources, ItemFields.MediaStreams],
|
||||
sortOrder: [SortOrder.Ascending],
|
||||
@@ -242,7 +248,7 @@ const PlayButton = ({
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
result = await getItemsApi(api).getItems({
|
||||
artistIds: [itemId],
|
||||
artistIds: [item.Id],
|
||||
recursive: true,
|
||||
includeItemTypes: [BaseItemKind.Audio],
|
||||
userId: userId,
|
||||
@@ -253,7 +259,7 @@ const PlayButton = ({
|
||||
break;
|
||||
case BaseItemKind.BoxSet:
|
||||
result = await getItemsApi(api).getItems({
|
||||
parentId: itemId,
|
||||
parentId: item.Id,
|
||||
userId,
|
||||
fields: [
|
||||
ItemFields.MediaSources,
|
||||
@@ -285,7 +291,7 @@ const PlayButton = ({
|
||||
break;
|
||||
default:
|
||||
result = await getItemsApi(api).getItems({
|
||||
ids: [itemId],
|
||||
ids: [item.Id],
|
||||
userId: userId,
|
||||
fields: [
|
||||
ItemFields.MediaSources,
|
||||
@@ -300,7 +306,7 @@ const PlayButton = ({
|
||||
audioStreamIndex: currentAudioTrack,
|
||||
subtitleStreamIndex:
|
||||
currentSubTrack === "nosub" ? -1 : currentSubTrack,
|
||||
itemId: itemId,
|
||||
itemId: item.Id,
|
||||
startTimeTicks:
|
||||
result.data.Items?.[0].UserData?.PlaybackPositionTicks,
|
||||
userId: userId,
|
||||
@@ -327,9 +333,15 @@ const PlayButton = ({
|
||||
api_key: api?.accessToken,
|
||||
};
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
const playbackUrl = `${api.basePath}/Audio/${result?.item.Items?.[0].Id}/universal?${urlParams}`;
|
||||
playAudio(playbackUrl, result?.item.Items?.[0], undefined);
|
||||
setQueue(result?.item.Items ?? [], 0);
|
||||
const playbackUrl = generateAudioStreamUrl(
|
||||
result?.item?.Items?.[0].Id,
|
||||
userId,
|
||||
api?.deviceInfo.id,
|
||||
api.basePath,
|
||||
api.accessToken,
|
||||
);
|
||||
playAudio(playbackUrl, result?.item?.Items?.[0], undefined);
|
||||
setQueue(result?.item?.Items ?? [], 0);
|
||||
} else if (item.Type === "Photo") {
|
||||
const index = result?.item?.Items?.map((i) => i.Id).indexOf(item.Id);
|
||||
if (result?.item?.Items && index) {
|
||||
|
||||
@@ -57,212 +57,82 @@ const AudioPlayer = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (display) {
|
||||
const audioUrlRequest = new Request(audioRef.current?.dataset.src, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: api.authorizationHeader,
|
||||
},
|
||||
});
|
||||
|
||||
const currentTrackItem = tracks[currentTrack];
|
||||
|
||||
fetch(audioUrlRequest)
|
||||
.then((res) => res)
|
||||
.then(async (result) => {
|
||||
const blob = await result.blob();
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
audioRef.current.src = blobUrl;
|
||||
await audioRef.current.play();
|
||||
if ("mediaSession" in navigator) {
|
||||
navigator.mediaSession.playbackState = "playing";
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: currentTrackItem.Name ?? "Unknown audio",
|
||||
artist: currentTrackItem.Artists?.join(", "),
|
||||
album: currentTrackItem.Album ?? "",
|
||||
artwork: [
|
||||
{
|
||||
src: getImageUrlsApi(api).getItemImageUrlById(
|
||||
currentTrackItem.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: currentTrackItem.ImageTags?.Primary,
|
||||
width: 96,
|
||||
height: 96,
|
||||
},
|
||||
),
|
||||
sizes: "96x96",
|
||||
type: "image/jpeg",
|
||||
},
|
||||
{
|
||||
src: getImageUrlsApi(api).getItemImageUrlById(
|
||||
currentTrackItem.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: currentTrackItem.ImageTags?.Primary,
|
||||
width: 128,
|
||||
height: 128,
|
||||
},
|
||||
),
|
||||
sizes: "128x128",
|
||||
type: "image/jpeg",
|
||||
},
|
||||
{
|
||||
src: getImageUrlsApi(api).getItemImageUrlById(
|
||||
currentTrackItem.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: currentTrackItem.ImageTags?.Primary,
|
||||
width: 192,
|
||||
height: 192,
|
||||
},
|
||||
),
|
||||
sizes: "192x192",
|
||||
type: "image/jpeg",
|
||||
},
|
||||
{
|
||||
src: getImageUrlsApi(api).getItemImageUrlById(
|
||||
currentTrackItem.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: currentTrackItem.ImageTags?.Primary,
|
||||
width: 256,
|
||||
height: 256,
|
||||
},
|
||||
),
|
||||
sizes: "256x256",
|
||||
type: "image/jpeg",
|
||||
},
|
||||
{
|
||||
src: getImageUrlsApi(api).getItemImageUrlById(
|
||||
currentTrackItem.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: currentTrackItem.ImageTags?.Primary,
|
||||
width: 384,
|
||||
height: 384,
|
||||
},
|
||||
),
|
||||
sizes: "384x384",
|
||||
type: "image/jpeg",
|
||||
},
|
||||
{
|
||||
src: getImageUrlsApi(api).getItemImageUrlById(
|
||||
currentTrackItem.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: currentTrackItem.ImageTags?.Primary,
|
||||
width: 512,
|
||||
height: 512,
|
||||
},
|
||||
),
|
||||
sizes: "512x512",
|
||||
type: "image/jpeg",
|
||||
},
|
||||
],
|
||||
});
|
||||
console.log("Using MediaSession Api");
|
||||
// navigator.mediaSession.setActionHandler("play", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("pause", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("stop", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("seekbackward", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("seekforward", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("seekto", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("previoustrack", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("nexttrack", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("skipad", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("togglecamera", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("togglemicrophone", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
// navigator.mediaSession.setActionHandler("hangup", () => {
|
||||
// /* Code excerpted. */
|
||||
// });
|
||||
}
|
||||
setLoading(false);
|
||||
});
|
||||
setAudioRef(audioRef);
|
||||
// const audioUrlRequest = new Request(audioRef.current?.dataset.src, {
|
||||
// method: "GET",
|
||||
// headers: {
|
||||
// Authorization: api.authorizationHeader,
|
||||
// },
|
||||
// });
|
||||
// fetch(audioUrlRequest)
|
||||
// .then((res) => res)
|
||||
// .then(async (result) => {
|
||||
// const blob = await result.blob();
|
||||
// const blobUrl = URL.createObjectURL(blob);
|
||||
// audioRef.current.src = blobUrl;
|
||||
// await audioRef.current.play();
|
||||
// setLoading(false);
|
||||
// });
|
||||
// setAudioRef(audioRef);
|
||||
}
|
||||
}, [url, tracks[currentTrack]?.Id]);
|
||||
}, [url, tracks?.[currentTrack]?.Id]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const info = useMemo(
|
||||
() => (
|
||||
<div
|
||||
// initial={{
|
||||
// filter: "opacity(0)",
|
||||
// }}
|
||||
// animate={{
|
||||
// filter: "opacity(1)",
|
||||
// }}
|
||||
// exit={{
|
||||
// filter: "opacity(0)",
|
||||
// }}
|
||||
className="audio-player-info"
|
||||
>
|
||||
<div className="audio-player-image-container">
|
||||
<img
|
||||
alt={tracks[currentTrack]?.Name ?? "track"}
|
||||
className="audio-player-image"
|
||||
src={
|
||||
!!api?.configuration?.apiKey &&
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
!item?.ImageTags.Primary ? item?.AlbumId : item?.Id,
|
||||
() =>
|
||||
!!api?.configuration && (
|
||||
<div
|
||||
// initial={{
|
||||
// filter: "opacity(0)",
|
||||
// }}
|
||||
// animate={{
|
||||
// filter: "opacity(1)",
|
||||
// }}
|
||||
// exit={{
|
||||
// filter: "opacity(0)",
|
||||
// }}
|
||||
className="audio-player-info"
|
||||
>
|
||||
<div className="audio-player-image-container">
|
||||
<img
|
||||
alt={tracks?.[currentTrack]?.Name ?? "track"}
|
||||
className="audio-player-image"
|
||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
||||
(!item?.ImageTags?.Primary ? item?.AlbumId : item?.Id) ?? "",
|
||||
"Primary",
|
||||
{
|
||||
quality: 85,
|
||||
fillHeight: 462,
|
||||
fillWidth: 462,
|
||||
},
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="material-symbols-rounded audio-player-image-icon">
|
||||
music_note
|
||||
</span>
|
||||
)}
|
||||
/>
|
||||
<span className="material-symbols-rounded audio-player-image-icon">
|
||||
music_note
|
||||
</span>
|
||||
</div>
|
||||
<div className="audio-player-info-text">
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
{item?.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
style={{
|
||||
opacity: 0.5,
|
||||
}}
|
||||
noWrap
|
||||
>
|
||||
by {item?.Artists?.map((artist) => artist).join(",")}
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
<div className="audio-player-info-text">
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
{item?.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
style={{
|
||||
opacity: 0.5,
|
||||
}}
|
||||
noWrap
|
||||
>
|
||||
by {item?.Artists?.map((artist) => artist).join(",")}
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
[tracks[currentTrack]?.Id, currentTrack],
|
||||
),
|
||||
[tracks?.[currentTrack]?.Id, currentTrack],
|
||||
);
|
||||
|
||||
const controls = useMemo(
|
||||
@@ -298,7 +168,7 @@ const AudioPlayer = () => {
|
||||
<PlayNextButton />
|
||||
</div>
|
||||
),
|
||||
[tracks[currentTrack]?.Id, loading, playing, tracks.length],
|
||||
[tracks?.[currentTrack]?.Id, loading, playing, tracks?.length],
|
||||
);
|
||||
|
||||
const buttons = useMemo(
|
||||
@@ -328,10 +198,12 @@ const AudioPlayer = () => {
|
||||
step={1}
|
||||
max={100}
|
||||
onChange={(_, newVal) => {
|
||||
Array.isArray(newVal)
|
||||
? setVolume(newVal[0] / 100)
|
||||
: setVolume(newVal / 100);
|
||||
audioRef.current.volume = newVal / 100;
|
||||
Array.isArray(newVal) ? setVolume(newVal[0] / 100) : setVolume(newVal / 100);
|
||||
if (Array.isArray(newVal)) {
|
||||
audioRef.current.volume = newVal[0] / 100;
|
||||
} else {
|
||||
audioRef.current.volume = newVal / 100;
|
||||
}
|
||||
}}
|
||||
valueLabelDisplay="auto"
|
||||
valueLabelFormat={(value) => Math.floor(value)}
|
||||
@@ -376,7 +248,7 @@ const AudioPlayer = () => {
|
||||
|
||||
if (audioRef.current) {
|
||||
audioRef.current.addEventListener("ended", () => {
|
||||
if (tracks[currentTrack + 1]?.Id) {
|
||||
if (tracks?.[currentTrack + 1]?.Id) {
|
||||
playItemFromQueue("next", user?.Id, api);
|
||||
}
|
||||
});
|
||||
@@ -409,7 +281,8 @@ const AudioPlayer = () => {
|
||||
>
|
||||
{info}
|
||||
<audio
|
||||
data-src={url}
|
||||
autoPlay
|
||||
src={url}
|
||||
ref={audioRef}
|
||||
key={item?.Id}
|
||||
onTimeUpdate={(e) =>
|
||||
@@ -451,8 +324,14 @@ const AudioPlayer = () => {
|
||||
onChangeCommitted={(_, value) => {
|
||||
setIsScrubbing(false);
|
||||
// console.log(ticksToSec(value * item?.RunTimeTicks));
|
||||
setProgress(value);
|
||||
audioRef.current.currentTime = ticksToSec(value);
|
||||
Array.isArray(value)
|
||||
? setProgress(value[0])
|
||||
: setProgress(value);
|
||||
if (Array.isArray(value)) {
|
||||
audioRef.current.currentTime = ticksToSec(value[0]);
|
||||
} else {
|
||||
audioRef.current.currentTime = ticksToSec(value);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Typography
|
||||
|
||||
@@ -7,7 +7,7 @@ import "./tagChip.scss";
|
||||
const TagChip = ({
|
||||
label,
|
||||
linkProps,
|
||||
}: { label: string; linkProps: LinkProps }) => {
|
||||
}: { label: string; linkProps?: LinkProps }) => {
|
||||
return (
|
||||
<Link className="tag" to="/search" search={{ query: label }} {...linkProps}>
|
||||
<Typography variant="subtitle2" fontWeight={300}>
|
||||
|
||||
+216
-143
@@ -1,16 +1,9 @@
|
||||
import PropTypes from "prop-types";
|
||||
import React, { useLayoutEffect, useRef } from "react";
|
||||
import React, { useLayoutEffect, useMemo, useRef } from "react";
|
||||
|
||||
import heroBg from "@/assets/herobg.png";
|
||||
import Box from "@mui/material/Box";
|
||||
import Chip from "@mui/material/Chip";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import useParallax from "@/utils/hooks/useParallax";
|
||||
import { motion, useScroll } from "framer-motion";
|
||||
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
@@ -18,27 +11,19 @@ import {
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
|
||||
import { Blurhash } from "react-blurhash";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
getRuntime,
|
||||
getRuntimeCompact,
|
||||
getRuntimeMusic,
|
||||
} from "@/utils/date/time";
|
||||
import { getRuntimeCompact, getRuntimeMusic } from "@/utils/date/time";
|
||||
|
||||
import { Card } from "@/components/card/card";
|
||||
import { CardScroller } from "@/components/cardScroller/cardScroller";
|
||||
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import PlayButton from "@/components/buttons/playButton";
|
||||
import TrackList from "@/components/layouts/tracksList";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import ShowMoreText from "@/components/showMoreText";
|
||||
|
||||
import { getTypeIcon } from "@/components/utils/iconsCollection";
|
||||
import {
|
||||
@@ -52,39 +37,10 @@ import "./album.scss";
|
||||
import TagChip from "@/components/tagChip";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { playItem } from "@/utils/store/playback";
|
||||
import { Link, createFileRoute } from "@tanstack/react-router";
|
||||
import lyricsIcon from "../../../assets/icons/lyrics.svg";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
|
||||
return (
|
||||
<div
|
||||
role="tabpanel"
|
||||
hidden={value !== index}
|
||||
id={`full-width-tabpanel-${index}`}
|
||||
aria-labelledby={`full-width-tab-${index}`}
|
||||
{...other}
|
||||
style={{ marginTop: "1em" }}
|
||||
>
|
||||
{value === index && <Box>{children}</Box>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
TabPanel.propTypes = {
|
||||
children: PropTypes.node,
|
||||
index: PropTypes.number.isRequired,
|
||||
value: PropTypes.number.isRequired,
|
||||
};
|
||||
|
||||
function a11yProps(index) {
|
||||
return {
|
||||
id: `full-width-tab-${index}`,
|
||||
"aria-controls": `full-width-tabpanel-${index}`,
|
||||
};
|
||||
}
|
||||
|
||||
export const Route = createFileRoute("/_api/album/$id")({
|
||||
component: MusicAlbumTitlePage,
|
||||
});
|
||||
@@ -112,12 +68,14 @@ function MusicAlbumTitlePage() {
|
||||
const similarItems = useQuery({
|
||||
queryKey: ["item", id, "similarItem"],
|
||||
queryFn: async () => {
|
||||
const result = await getLibraryApi(api).getSimilarAlbums({
|
||||
userId: user?.Id,
|
||||
itemId: item.data?.Id,
|
||||
limit: 16,
|
||||
});
|
||||
return result.data;
|
||||
if (item.data?.Id) {
|
||||
const result = await getLibraryApi(api).getSimilarAlbums({
|
||||
userId: user?.Id,
|
||||
itemId: item.data?.Id,
|
||||
limit: 16,
|
||||
});
|
||||
return result.data;
|
||||
}
|
||||
},
|
||||
enabled: item.isSuccess,
|
||||
networkMode: "always",
|
||||
@@ -132,6 +90,7 @@ function MusicAlbumTitlePage() {
|
||||
parentId: item.data?.Id,
|
||||
sortOrder: [SortOrder.Ascending],
|
||||
sortBy: ["IndexNumber"],
|
||||
fields: ["MediaSources"],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
@@ -141,6 +100,21 @@ function MusicAlbumTitlePage() {
|
||||
|
||||
const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]);
|
||||
|
||||
const allDiscs = useMemo(() => {
|
||||
const discs: number[] = [];
|
||||
if (musicTracks.data?.Items) {
|
||||
for (const track of musicTracks.data.Items) {
|
||||
if (
|
||||
track.ParentIndexNumber &&
|
||||
!discs.includes(track.ParentIndexNumber)
|
||||
) {
|
||||
discs.push(track.ParentIndexNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
return discs;
|
||||
}, [musicTracks.data]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (item.isSuccess) {
|
||||
setAppBackdrop(
|
||||
@@ -151,24 +125,22 @@ function MusicAlbumTitlePage() {
|
||||
}, [item.isSuccess]);
|
||||
|
||||
const pageRef = useRef(null);
|
||||
const { scrollYProgress } = useScroll({
|
||||
target: pageRef,
|
||||
offset: ["start start", "60vh start"],
|
||||
});
|
||||
const parallax = useParallax(scrollYProgress, 50);
|
||||
|
||||
const handlePlayback = (
|
||||
index: number,
|
||||
item: BaseItemDto,
|
||||
queue: BaseItemDto[],
|
||||
) => {
|
||||
const url = generateAudioStreamUrl(
|
||||
item.Id,
|
||||
user?.Id,
|
||||
api.deviceInfo.id,
|
||||
api.basePath,
|
||||
);
|
||||
playAudio(url, item, undefined, queue, index);
|
||||
if (item.Id && user?.Id) {
|
||||
const url = generateAudioStreamUrl(
|
||||
item.Id,
|
||||
user?.Id,
|
||||
api.deviceInfo.id,
|
||||
api.basePath,
|
||||
api.accessToken,
|
||||
);
|
||||
playAudio(url, item, undefined);
|
||||
}
|
||||
};
|
||||
|
||||
const currentPlayingItem = useAudioPlayback((s) => s.item);
|
||||
@@ -216,19 +188,19 @@ function MusicAlbumTitlePage() {
|
||||
{item.data.ProductionYear}
|
||||
</Typography>
|
||||
<Typography className="opacity-07">
|
||||
{musicTracks.data?.TotalRecordCount > 1
|
||||
{(musicTracks.data?.TotalRecordCount ?? 0) > 1
|
||||
? `${musicTracks.data?.TotalRecordCount} songs`
|
||||
: `1 song`}
|
||||
: "1 song"}
|
||||
</Typography>
|
||||
<Typography className="opacity-07">
|
||||
{getRuntimeCompact(item.data.CumulativeRunTimeTicks)}
|
||||
{getRuntimeCompact(item.data.CumulativeRunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-buttons">
|
||||
<PlayButton
|
||||
item={item}
|
||||
item={item.data}
|
||||
audio
|
||||
itemType={item.data.Type}
|
||||
itemType={item.data.Type ?? "Audio"}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<LikeButton
|
||||
@@ -239,62 +211,157 @@ function MusicAlbumTitlePage() {
|
||||
itemName={item.data.Name}
|
||||
/>
|
||||
</div>
|
||||
<div className="item-info-track-container">
|
||||
<div className="item-info-track header">
|
||||
<span className="material-symbols-rounded index">tag</span>
|
||||
<Typography variant="subtitle1">Title</Typography>
|
||||
<Typography variant="subtitle1">Duration</Typography>
|
||||
</div>
|
||||
{musicTracks.data?.Items?.map((track, index) => (
|
||||
<div
|
||||
className={
|
||||
currentPlayingItem?.Id === track.Id
|
||||
? "item-info-track playing"
|
||||
: "item-info-track"
|
||||
}
|
||||
key={track.Id}
|
||||
onClick={() =>
|
||||
handlePlayback(index, track, musicTracks.data.Items)
|
||||
}
|
||||
>
|
||||
<div className="index-container">
|
||||
<span className="material-symbols-rounded fill ">
|
||||
play_arrow
|
||||
</span>
|
||||
<Typography className="index">
|
||||
{track.IndexNumber ?? "-"}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-track-info">
|
||||
<Typography className="item-info-track-info-name">
|
||||
{track.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
opacity: 0.6,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.6em",
|
||||
}}
|
||||
fontWeight={300}
|
||||
<div className="item-info-track-container ">
|
||||
{allDiscs.length > 0 ? (
|
||||
allDiscs.map((disc) => (
|
||||
<>
|
||||
<div
|
||||
className="item-info-disc-header flex flex-row flex-align-center"
|
||||
key={disc}
|
||||
>
|
||||
{track.HasLyrics && <img src={lyricsIcon} alt="lyrics" />}
|
||||
{track.Artists?.join(", ")}
|
||||
</Typography>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "2em" }}
|
||||
>
|
||||
album
|
||||
</span>
|
||||
<Typography variant="h5">Disc {disc}</Typography>
|
||||
</div>
|
||||
<div key={disc} className="item-info-track header">
|
||||
<span className="material-symbols-rounded index">
|
||||
tag
|
||||
</span>
|
||||
<Typography variant="subtitle1">Title</Typography>
|
||||
<Typography variant="subtitle1">Duration</Typography>
|
||||
</div>
|
||||
{musicTracks.data?.Items?.map(
|
||||
(track, index) =>
|
||||
track.ParentIndexNumber === disc && (
|
||||
<div
|
||||
className={
|
||||
currentPlayingItem?.Id === track.Id
|
||||
? "item-info-track playing"
|
||||
: "item-info-track"
|
||||
}
|
||||
key={track.Id}
|
||||
onClick={() =>
|
||||
musicTracks.data.Items &&
|
||||
handlePlayback(
|
||||
index,
|
||||
track,
|
||||
musicTracks.data.Items,
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="index-container">
|
||||
<span className="material-symbols-rounded fill ">
|
||||
play_arrow
|
||||
</span>
|
||||
<Typography className="index">
|
||||
{track.IndexNumber ?? "-"}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-track-info">
|
||||
<Typography className="item-info-track-info-name">
|
||||
{track.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
opacity: 0.6,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.6em",
|
||||
}}
|
||||
fontWeight={300}
|
||||
>
|
||||
{track.HasLyrics && (
|
||||
<img src={lyricsIcon} alt="lyrics" />
|
||||
)}
|
||||
{track.Artists?.join(", ")}
|
||||
</Typography>
|
||||
</div>
|
||||
<Typography>
|
||||
{getRuntimeMusic(track.RunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
<div className="flex flex-align-center">
|
||||
<LikeButton
|
||||
itemId={track.Id}
|
||||
isFavorite={track.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user?.Id}
|
||||
itemName={track.Name}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</>
|
||||
))
|
||||
) : (
|
||||
<>
|
||||
<div className="item-info-track header">
|
||||
<span className="material-symbols-rounded index">tag</span>
|
||||
<Typography variant="subtitle1">Title</Typography>
|
||||
<Typography variant="subtitle1">Duration</Typography>
|
||||
</div>
|
||||
<Typography>{getRuntimeMusic(track.RunTimeTicks)}</Typography>
|
||||
<div className="flex flex-align-center">
|
||||
<LikeButton
|
||||
itemId={track.Id}
|
||||
isFavorite={track.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user?.Id}
|
||||
itemName={track.Name}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{musicTracks.data?.Items?.map((track, index) => (
|
||||
<div
|
||||
className={
|
||||
currentPlayingItem?.Id === track.Id
|
||||
? "item-info-track playing"
|
||||
: "item-info-track"
|
||||
}
|
||||
key={track.Id}
|
||||
onClick={() =>
|
||||
musicTracks.data.Items &&
|
||||
handlePlayback(index, track, musicTracks.data.Items)
|
||||
}
|
||||
>
|
||||
<div className="index-container">
|
||||
<span className="material-symbols-rounded fill ">
|
||||
play_arrow
|
||||
</span>
|
||||
<Typography className="index">
|
||||
{track.IndexNumber ?? "-"}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-track-info">
|
||||
<Typography className="item-info-track-info-name">
|
||||
{track.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
opacity: 0.6,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.6em",
|
||||
}}
|
||||
fontWeight={300}
|
||||
>
|
||||
{track.HasLyrics && (
|
||||
<img src={lyricsIcon} alt="lyrics" />
|
||||
)}
|
||||
{track.Artists?.join(", ")}
|
||||
</Typography>
|
||||
</div>
|
||||
<Typography>
|
||||
{getRuntimeMusic(track.RunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
<div className="flex flex-align-center">
|
||||
<LikeButton
|
||||
itemId={track.Id}
|
||||
isFavorite={track.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user?.Id}
|
||||
itemName={track.Name}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="item-info-sidebar">
|
||||
@@ -303,14 +370,17 @@ function MusicAlbumTitlePage() {
|
||||
<img
|
||||
className="item-info-sidebar-image"
|
||||
alt={item.data.Name ?? "Album"}
|
||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
||||
item.data.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: item.data.ImageTags.Primary,
|
||||
quality: 90,
|
||||
},
|
||||
)}
|
||||
src={
|
||||
item.data.Id &&
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
item.data.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: item.data.ImageTags.Primary,
|
||||
quality: 90,
|
||||
},
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<div className="item-info-sidebar-icon">
|
||||
@@ -323,14 +393,14 @@ function MusicAlbumTitlePage() {
|
||||
style={{ gap: "1em", flexWrap: "wrap" }}
|
||||
>
|
||||
{item.data.GenreItems?.map((genre) => (
|
||||
<TagChip label={genre.Name} key={genre.Id} />
|
||||
<TagChip label={genre.Name ?? "genre"} key={genre.Id} />
|
||||
))}
|
||||
</div>
|
||||
<div className="flex flex-column item-info-sidebar-artist-container">
|
||||
{item.data.ArtistItems?.map((artist) => (
|
||||
<Link
|
||||
to="/artist/$id"
|
||||
params={{ id: artist.Id }}
|
||||
params={{ id: artist.Id ?? "" }}
|
||||
className="item-info-sidebar-artist"
|
||||
key={artist.Id}
|
||||
>
|
||||
@@ -338,13 +408,16 @@ function MusicAlbumTitlePage() {
|
||||
<img
|
||||
className="item-info-sidebar-artist-image"
|
||||
alt={artist.Name ?? "Artist"}
|
||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
||||
artist.Id,
|
||||
"Primary",
|
||||
{
|
||||
quality: 90,
|
||||
},
|
||||
)}
|
||||
src={
|
||||
artist.Id &&
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
artist.Id,
|
||||
"Primary",
|
||||
{
|
||||
quality: 90,
|
||||
},
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="material-symbols-rounded">artist</span>
|
||||
</div>
|
||||
@@ -354,13 +427,13 @@ function MusicAlbumTitlePage() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{(similarItems.data.TotalRecordCount ?? -1) > 0 && (
|
||||
{(similarItems.data?.TotalRecordCount ?? -1) > 0 && (
|
||||
<CardScroller
|
||||
title="You might also like"
|
||||
displayCards={7}
|
||||
disableDecoration
|
||||
>
|
||||
{similarItems.data.Items?.map((similar) => {
|
||||
{similarItems.data?.Items?.map((similar) => {
|
||||
return (
|
||||
<Card
|
||||
key={similar.Id}
|
||||
|
||||
@@ -133,6 +133,13 @@ $border-radius: 20px;
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
}
|
||||
&-disc-header{
|
||||
padding: 1em 2em;
|
||||
background: hsla(0, 0, 100%, 10%);
|
||||
border-radius: 100px;
|
||||
gap: 1em;
|
||||
margin-top: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
.item-detail-album {
|
||||
|
||||
@@ -43,7 +43,7 @@ import TrailerButton from "@/components/buttons/trailerButton";
|
||||
import ShowMoreText from "@/components/showMoreText";
|
||||
import { getTypeIcon } from "@/components/utils/iconsCollection";
|
||||
import { endsAt, getRuntime } from "@/utils/date/time";
|
||||
import { setBackdrop, useBackdropStore } from "@/utils/store/backdrop";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
|
||||
import ItemSkeleton from "@/components/skeleton/item";
|
||||
|
||||
@@ -194,11 +194,13 @@ function ItemDetail() {
|
||||
|
||||
const [mediaQualityInfo, setMediaQualityInfo] = useState<MediaQualityInfo>();
|
||||
|
||||
const setBackdrop = useBackdropStore((state) => state.setBackdrop);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (item.isSuccess) {
|
||||
if (item.data.BackdropImageTags?.length > 0) {
|
||||
setBackdrop(
|
||||
getImageUrlsApi(api).getItemImageUrl(item.data.Id, "Backdrop", {
|
||||
getImageUrlsApi(api).getItemImageUrlById(item.data.Id, "Backdrop", {
|
||||
tag: item.data.BackdropImageTags[0],
|
||||
}),
|
||||
item.data.BackdropImageTags[0],
|
||||
|
||||
@@ -2,10 +2,13 @@ import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { create } from "zustand";
|
||||
import { setQueue } from "./queue";
|
||||
|
||||
import { start } from "repl";
|
||||
import { max } from "lodash";
|
||||
import type React from "react";
|
||||
import { shallow } from "zustand/shallow";
|
||||
import { createWithEqualityFn } from "zustand/traditional";
|
||||
import { secToTicks } from "../date/time";
|
||||
import playbackProfile from "../playback-profiles";
|
||||
|
||||
type AudioPlaybackStore = {
|
||||
display: boolean;
|
||||
@@ -51,10 +54,41 @@ export const generateAudioStreamUrl = (
|
||||
userId: string,
|
||||
deviceId: string,
|
||||
basePath: string,
|
||||
api_key: string,
|
||||
) => {
|
||||
const transcodingProfile = playbackProfile.TranscodingProfiles?.filter(
|
||||
(val) => val.Type === "Audio" && val.Context === "Streaming",
|
||||
)[0];
|
||||
|
||||
let directPlayContainers = "";
|
||||
if (playbackProfile.DirectPlayProfiles) {
|
||||
for (const p of playbackProfile.DirectPlayProfiles) {
|
||||
if (p.Type === "Audio") {
|
||||
if (directPlayContainers) {
|
||||
directPlayContainers += `, ${p.Container}`;
|
||||
} else {
|
||||
directPlayContainers = p.Container ?? "";
|
||||
}
|
||||
|
||||
if (p.AudioCodec) {
|
||||
directPlayContainers += `| ${p.AudioCodec}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const urlOptions = {
|
||||
userId,
|
||||
deviceId,
|
||||
api_key,
|
||||
container: directPlayContainers,
|
||||
maxAudioChannels: transcodingProfile?.MaxAudioChannels,
|
||||
transcodingContainer: transcodingProfile?.Container,
|
||||
transcodingProtocol: transcodingProfile?.Protocol,
|
||||
audioCodec: transcodingProfile?.AudioCodec,
|
||||
playSessionId: new Date().getTime(),
|
||||
startTimeTicks: 0,
|
||||
enableRemoteMedia: false,
|
||||
enableAudioVbrEncoding: true,
|
||||
};
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
return `${basePath}/Audio/${itemId}/universal?${urlParams}`;
|
||||
|
||||
Reference in new issue
Block a user