Send progress update to server when playing media #10
This commit is contained in:
4 files changed
+237
-18
No files matched your search
+188
-14
@@ -26,7 +26,7 @@ import MenuItem from "@mui/material/MenuItem";
|
|||||||
import Link from "@mui/material/Link";
|
import Link from "@mui/material/Link";
|
||||||
import { green, pink, yellow } from "@mui/material/colors";
|
import { green, pink, yellow } from "@mui/material/colors";
|
||||||
|
|
||||||
import { motion } from "framer-motion";
|
import { AnimatePresence, motion } from "framer-motion";
|
||||||
|
|
||||||
import { Blurhash } from "react-blurhash";
|
import { Blurhash } from "react-blurhash";
|
||||||
import { useParams, useNavigate, Link as RouterLink } from "react-router-dom";
|
import { useParams, useNavigate, Link as RouterLink } from "react-router-dom";
|
||||||
@@ -117,6 +117,7 @@ const ItemDetail = () => {
|
|||||||
const result = await getUserLibraryApi(window.api).getItem({
|
const result = await getUserLibraryApi(window.api).getItem({
|
||||||
userId: user.data.Id,
|
userId: user.data.Id,
|
||||||
itemId: id,
|
itemId: id,
|
||||||
|
fields: [ItemFields.Crew],
|
||||||
});
|
});
|
||||||
return result.data;
|
return result.data;
|
||||||
},
|
},
|
||||||
@@ -510,10 +511,29 @@ const ItemDetail = () => {
|
|||||||
}
|
}
|
||||||
}, [item.isSuccess]);
|
}, [item.isSuccess]);
|
||||||
|
|
||||||
const [url, setUrl] = usePlaybackStore((state) => [
|
const [setUrl, setPosition, setItemId, setItemName] = usePlaybackStore(
|
||||||
state.url,
|
(state) => [
|
||||||
state.setUrl,
|
state.setUrl,
|
||||||
]);
|
state.setPosition,
|
||||||
|
state.setItemId,
|
||||||
|
state.setItemName,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
const [directors, setDirectors] = useState([]);
|
||||||
|
const [writers, setWriters] = useState([]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (item.isSuccess) {
|
||||||
|
let direTp = item.data.People.filter(
|
||||||
|
(itm) => itm.Type == "Director",
|
||||||
|
);
|
||||||
|
setDirectors(direTp);
|
||||||
|
let writeTp = item.data.People.filter(
|
||||||
|
(itm) => itm.Type == "Writer",
|
||||||
|
);
|
||||||
|
setWriters(writeTp);
|
||||||
|
}
|
||||||
|
}, [item.isSuccess]);
|
||||||
|
|
||||||
if (item.isLoading || similarItems.isLoading) {
|
if (item.isLoading || similarItems.isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -1005,6 +1025,22 @@ const ItemDetail = () => {
|
|||||||
setUrl(
|
setUrl(
|
||||||
`${window.api.basePath}/Videos/${item.data.Id}/stream.${item.data.MediaSources[0].Container}?Static=true&mediaSourceId=${item.data.Id}&deviceId=${window.api.deviceInfo.id}&api_key=${window.api.accessToken}&Tag=${item.data.MediaSources[0].ETag}`,
|
`${window.api.basePath}/Videos/${item.data.Id}/stream.${item.data.MediaSources[0].Container}?Static=true&mediaSourceId=${item.data.Id}&deviceId=${window.api.deviceInfo.id}&api_key=${window.api.accessToken}&Tag=${item.data.MediaSources[0].ETag}`,
|
||||||
);
|
);
|
||||||
|
setPosition(
|
||||||
|
item
|
||||||
|
.data
|
||||||
|
.UserData
|
||||||
|
.PlaybackPositionTicks,
|
||||||
|
);
|
||||||
|
setItemName(
|
||||||
|
item
|
||||||
|
.data
|
||||||
|
.Name,
|
||||||
|
);
|
||||||
|
setItemId(
|
||||||
|
item
|
||||||
|
.data
|
||||||
|
.Id,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
navigate(
|
navigate(
|
||||||
`/player`,
|
`/player`,
|
||||||
@@ -1286,23 +1322,161 @@ const ItemDetail = () => {
|
|||||||
<TableCell>
|
<TableCell>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
gap={1}
|
gap={0.5}
|
||||||
|
divider={
|
||||||
|
<Typography variant="h6">
|
||||||
|
,
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
width="100%"
|
||||||
>
|
>
|
||||||
{item.data.Genres.map(
|
{item.data.Studios.map(
|
||||||
(
|
(
|
||||||
genre,
|
item,
|
||||||
index,
|
index,
|
||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
<Chip
|
<Link
|
||||||
|
component={
|
||||||
|
RouterLink
|
||||||
|
}
|
||||||
key={
|
key={
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
variant="filled"
|
to={`/item/${item.Id}`}
|
||||||
label={
|
color="inherit"
|
||||||
genre
|
variant="h6"
|
||||||
|
underline="hover"
|
||||||
|
noWrap
|
||||||
|
>
|
||||||
|
{
|
||||||
|
item.Name
|
||||||
}
|
}
|
||||||
/>
|
</Link>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
{directors.length != 0 && (
|
||||||
|
<TableRow
|
||||||
|
sx={{
|
||||||
|
"& td, & th": {
|
||||||
|
border: 0,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TableCell
|
||||||
|
sx={{
|
||||||
|
paddingLeft: 0,
|
||||||
|
width: "5%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
className="item-detail-heading"
|
||||||
|
variant="h5"
|
||||||
|
mr={2}
|
||||||
|
>
|
||||||
|
Director
|
||||||
|
</Typography>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={0.5}
|
||||||
|
divider={
|
||||||
|
<Typography variant="h6">
|
||||||
|
,
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{directors.map(
|
||||||
|
(
|
||||||
|
item,
|
||||||
|
index,
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
component={
|
||||||
|
RouterLink
|
||||||
|
}
|
||||||
|
key={
|
||||||
|
index
|
||||||
|
}
|
||||||
|
to={`/item/${item.Id}`}
|
||||||
|
color="inherit"
|
||||||
|
variant="h6"
|
||||||
|
underline="hover"
|
||||||
|
noWrap
|
||||||
|
>
|
||||||
|
{
|
||||||
|
item.Name
|
||||||
|
}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
{writers.length != 0 && (
|
||||||
|
<TableRow
|
||||||
|
sx={{
|
||||||
|
"& td, & th": {
|
||||||
|
border: 0,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TableCell
|
||||||
|
sx={{
|
||||||
|
paddingLeft: 0,
|
||||||
|
width: "5%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
className="item-detail-heading"
|
||||||
|
variant="h5"
|
||||||
|
mr={2}
|
||||||
|
>
|
||||||
|
Writers
|
||||||
|
</Typography>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={0.5}
|
||||||
|
divider={
|
||||||
|
<Typography variant="h6">
|
||||||
|
,
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{writers.map(
|
||||||
|
(
|
||||||
|
item,
|
||||||
|
index,
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
component={
|
||||||
|
RouterLink
|
||||||
|
}
|
||||||
|
key={
|
||||||
|
index
|
||||||
|
}
|
||||||
|
to={`/item/${item.Id}`}
|
||||||
|
color="inherit"
|
||||||
|
variant="h6"
|
||||||
|
underline="hover"
|
||||||
|
noWrap
|
||||||
|
>
|
||||||
|
{
|
||||||
|
item.Name
|
||||||
|
}
|
||||||
|
</Link>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
@@ -2572,7 +2746,7 @@ const ItemDetail = () => {
|
|||||||
duration: 0.35,
|
duration: 0.35,
|
||||||
delay:
|
delay:
|
||||||
mindex *
|
mindex *
|
||||||
0.05,
|
0.1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<EpisodeCard
|
<EpisodeCard
|
||||||
|
|||||||
@@ -16,11 +16,23 @@ import { usePlaybackStore } from "../../utils/store/playback";
|
|||||||
|
|
||||||
import AppBar from "@mui/material/AppBar";
|
import AppBar from "@mui/material/AppBar";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { MdiChevronLeft } from "../../components/icons/mdiChevronLeft";
|
import { MdiChevronLeft } from "../../components/icons/mdiChevronLeft";
|
||||||
|
|
||||||
|
import { secToTicks, ticksToSec } from "../../utils/date/time";
|
||||||
|
|
||||||
|
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||||
|
|
||||||
const VideoPlayer = () => {
|
const VideoPlayer = () => {
|
||||||
const url = usePlaybackStore((state) => state.url);
|
const [url, startPosition, itemId, itemName] = usePlaybackStore(
|
||||||
|
(state) => [
|
||||||
|
state.url,
|
||||||
|
state.startPosition,
|
||||||
|
state.itemId,
|
||||||
|
state.itemName,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -42,7 +54,6 @@ const VideoPlayer = () => {
|
|||||||
const handlePlayerReady = (player) => {
|
const handlePlayerReady = (player) => {
|
||||||
playerRef.current = player;
|
playerRef.current = player;
|
||||||
|
|
||||||
// You can handle player events here, for example:
|
|
||||||
player.on("waiting", () => {
|
player.on("waiting", () => {
|
||||||
videojs.log("player is waiting");
|
videojs.log("player is waiting");
|
||||||
});
|
});
|
||||||
@@ -50,6 +61,17 @@ const VideoPlayer = () => {
|
|||||||
player.on("dispose", () => {
|
player.on("dispose", () => {
|
||||||
videojs.log("player will dispose");
|
videojs.log("player will dispose");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
player.on("progress", async () => {
|
||||||
|
await getPlaystateApi(window.api).reportPlaybackProgress({
|
||||||
|
playbackProgressInfo: {
|
||||||
|
ItemId: itemId,
|
||||||
|
PlaybackStartTimeTicks: startPosition,
|
||||||
|
PositionTicks: secToTicks(player.currentTime()),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
player.currentTime(ticksToSec(startPosition));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+18
-1
@@ -3,11 +3,28 @@
|
|||||||
* @param {number} ticks - C# ticks of a particular item
|
* @param {number} ticks - C# ticks of a particular item
|
||||||
* @return {number} Converted ticks to Milliseconds
|
* @return {number} Converted ticks to Milliseconds
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const ticksToMs = (ticks) => {
|
const ticksToMs = (ticks) => {
|
||||||
return Math.round(ticks / 10000);
|
return Math.round(ticks / 10000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @format
|
||||||
|
* @param {number} ticks - C# ticks of a particular item
|
||||||
|
* @return {number} Converted ticks to Seconds
|
||||||
|
*/
|
||||||
|
export const ticksToSec = (ticks) => {
|
||||||
|
return Math.round(ticksToMs(ticks) / 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @format
|
||||||
|
* @param {number} sec - Sec of a particular item
|
||||||
|
* @return {number} Converted Seconds to C# ticks
|
||||||
|
*/
|
||||||
|
export const secToTicks = (ticks) => {
|
||||||
|
return Math.round(ticks * 10000000);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @format
|
* @format
|
||||||
* @param {number} ticks - C# ticks of a particular item
|
* @param {number} ticks - C# ticks of a particular item
|
||||||
|
|||||||
@@ -4,5 +4,11 @@ import { create } from "zustand";
|
|||||||
|
|
||||||
export const usePlaybackStore = create((set) => ({
|
export const usePlaybackStore = create((set) => ({
|
||||||
url: "",
|
url: "",
|
||||||
setUrl: (aurl) => set(() => ({ url: aurl })),
|
startPosition: 0,
|
||||||
|
itemId: "",
|
||||||
|
itemName: "",
|
||||||
|
setUrl: (aurl) => set((state) => ({ ...state, url: aurl })),
|
||||||
|
setPosition: (apos) => set((state) => ({ ...state, startPosition: apos })),
|
||||||
|
setItemId: (aid) => set((state) => ({ ...state, itemId: aid })),
|
||||||
|
setItemName: (anm) => set((state) => ({ ...state, itemName: anm })),
|
||||||
}));
|
}));
|
||||||
Reference in new issue
Block a user