Skip to content

Commit

Permalink
Report playback end
Browse files Browse the repository at this point in the history
  • Loading branch information
prayag17 committed Dec 7, 2023
1 parent e095863 commit 0af246c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/buttons/playButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LinearProgress from "@mui/material/LinearProgress";
import Typography from "@mui/material/Typography";

import {
setItem,
usePlaybackDataLoadStore,
usePlaybackStore,
} from "../../utils/store/playback";
Expand Down Expand Up @@ -210,6 +211,7 @@ const PlayButton = ({
setSubtitleStreamIndex(currentSubTrack);

setMediaSourceId(item.Items[0].Id);
setItem(item.Items[0]);

switch (item.Items[0].Type) {
case BaseItemKind.Movie:
Expand Down
4 changes: 2 additions & 2 deletions src/components/card/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const Card = ({
aspectRatio: cardImageAspectRatios[cardType],
}}
>
{/* {!!item.UserData && (
{!!item.UserData && (
<>
<div
className="card-indicator check"
Expand Down Expand Up @@ -133,7 +133,7 @@ export const Card = ({
</Typography>
</div>
</>
)} */}
)}
{/* {!!imageBlurhash && (
<Blurhash
hash={imageBlurhash}
Expand Down
13 changes: 13 additions & 0 deletions src/routes/player/videoPlayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const VideoPlayer = () => {
setMediaSourceId,
setUserId,
setSeriesId,
item,
] = usePlaybackStore((state) => [
state.url,
state.startPosition,
Expand All @@ -104,6 +105,7 @@ export const VideoPlayer = () => {
state.setMediaSourceId,
state.setUserId,
state.setSeriesId,
state.item,
]);

const mediaInfo = useQuery({
Expand Down Expand Up @@ -504,6 +506,17 @@ export const VideoPlayer = () => {
const handleExit = async () => {
// Remove app from fullscreen
await appWindow.setFullscreen(false);
// Send playback end report
await getPlaystateApi(api).reportPlaybackStopped({
playbackStopInfo: {
Failed: false,
Item: item,
ItemId: itemId,
MediaSourceId: mediaInfo.data?.MediaSources[0].Id,
PlaySessionId: mediaInfo.data?.PlaySessionId,
PositionTicks: currentTime,
},
});
navigate(-1);

// Reset playback store
Expand Down
6 changes: 6 additions & 0 deletions src/utils/store/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const usePlaybackStore = create((set) => ({
seriesId: "",
queue: [],
episodeIndex: 0,
/**
* @type {import("@jellyfin/sdk/lib/generated-client/models/base-item-dto").BaseItemDto}
*/
item: {},
setUrl: (aurl) => set((state) => ({ ...state, url: aurl })),
setPosition: (apos) => set((state) => ({ ...state, startPosition: apos })),
setDuration: (adur) => set((state) => ({ ...state, duration: adur })),
Expand Down Expand Up @@ -47,6 +51,8 @@ export const usePlaybackStore = create((set) => ({
setEpisodeIndex: (aitem) =>
set((state) => ({ ...state, episodeIndex: aitem })),
}));
export const setItem = (item) =>
usePlaybackStore.setState((state) => ({ ...state, item: item }));

export const usePlaybackDataLoadStore = create((set) => ({
isPending: false,
Expand Down

0 comments on commit 0af246c

Please sign in to comment.