fix: display and report correct playback method
This commit is contained in:
7 files changed
+72
-23
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
type BaseItemDto,
|
type BaseItemDto,
|
||||||
BaseItemKind,
|
BaseItemKind,
|
||||||
|
PlayMethod,
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||||
import type { SxProps } from "@mui/material";
|
import type { SxProps } from "@mui/material";
|
||||||
@@ -229,8 +230,17 @@ const PlayButton = ({
|
|||||||
};
|
};
|
||||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||||
let playbackUrl = `${api?.basePath}/Videos/${result?.mediaSource.MediaSources?.[0].Id}/stream.${result?.mediaSource.MediaSources?.[0].Container}?${urlParams}`;
|
let playbackUrl = `${api?.basePath}/Videos/${result?.mediaSource.MediaSources?.[0].Id}/stream.${result?.mediaSource.MediaSources?.[0].Container}?${urlParams}`;
|
||||||
|
|
||||||
|
const source = result.mediaSource.MediaSources?.[0];
|
||||||
|
let playMethod = PlayMethod.Transcode;
|
||||||
|
if (source?.SupportsDirectPlay) {
|
||||||
|
playMethod = PlayMethod.DirectPlay;
|
||||||
|
} else if (source?.SupportsDirectStream) {
|
||||||
|
playMethod = PlayMethod.DirectStream;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
result?.mediaSource.MediaSources?.[0].SupportsTranscoding &&
|
playMethod === PlayMethod.Transcode &&
|
||||||
result?.mediaSource.MediaSources?.[0].TranscodingUrl
|
result?.mediaSource.MediaSources?.[0].TranscodingUrl
|
||||||
) {
|
) {
|
||||||
playbackUrl = `${api.basePath}${result.mediaSource.MediaSources[0].TranscodingUrl}`;
|
playbackUrl = `${api.basePath}${result.mediaSource.MediaSources[0].TranscodingUrl}`;
|
||||||
@@ -248,10 +258,6 @@ const PlayButton = ({
|
|||||||
(value) => value.Type === "Video",
|
(value) => value.Type === "Video",
|
||||||
);
|
);
|
||||||
|
|
||||||
const isDirectPlay =
|
|
||||||
!result.mediaSource.MediaSources?.[0].SupportsTranscoding ||
|
|
||||||
!result.mediaSource.MediaSources?.[0].TranscodingUrl;
|
|
||||||
|
|
||||||
playItem({
|
playItem({
|
||||||
metadata: {
|
metadata: {
|
||||||
itemName: itemName ?? "",
|
itemName: itemName ?? "",
|
||||||
@@ -283,7 +289,7 @@ const PlayButton = ({
|
|||||||
audioCodec:
|
audioCodec:
|
||||||
audio.allTracks?.find((t) => t.Index === audio.track)?.Codec ??
|
audio.allTracks?.find((t) => t.Index === audio.track)?.Codec ??
|
||||||
"",
|
"",
|
||||||
isDirectPlay: isDirectPlay,
|
playMethod: playMethod,
|
||||||
transcodingUrl:
|
transcodingUrl:
|
||||||
result.mediaSource.MediaSources?.[0].TranscodingUrl ?? "",
|
result.mediaSource.MediaSources?.[0].TranscodingUrl ?? "",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ const StatsForNerds = ({ playerRef }: StatsForNerdsProps) => {
|
|||||||
<span>Media Source ID:</span> <span>{mediaSourceId}</span>
|
<span>Media Source ID:</span> <span>{mediaSourceId}</span>
|
||||||
<span>Play Session ID:</span> <span>{playsessionId}</span>
|
<span>Play Session ID:</span> <span>{playsessionId}</span>
|
||||||
<span>Playback Method:</span>{" "}
|
<span>Playback Method:</span>{" "}
|
||||||
<span>{mediaSource.isDirectPlay ? "Direct Play" : "Transcoding"}</span>
|
<span>{mediaSource.playMethod}</span>
|
||||||
<span>Container:</span> <span>{mediaSource.container}</span>
|
<span>Container:</span> <span>{mediaSource.container}</span>
|
||||||
<span>Video Codec:</span> <span>{mediaSource.videoCodec}</span>
|
<span>Video Codec:</span> <span>{mediaSource.videoCodec}</span>
|
||||||
<span>Audio Codec:</span> <span>{mediaSource.audioCodec}</span>
|
<span>Audio Codec:</span> <span>{mediaSource.audioCodec}</span>
|
||||||
|
|||||||
@@ -147,9 +147,6 @@ function BoxSetTitlePage() {
|
|||||||
<PlayButton
|
<PlayButton
|
||||||
item={item.data}
|
item={item.data}
|
||||||
itemType={item.data.Type ?? "BoxSet"}
|
itemType={item.data.Type ?? "BoxSet"}
|
||||||
currentVideoTrack={0}
|
|
||||||
currentAudioTrack={0}
|
|
||||||
currentSubTrack={0}
|
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
fullWidth: true,
|
fullWidth: true,
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ export function VideoPlayer() {
|
|||||||
IsPaused: false,
|
IsPaused: false,
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
MediaSourceId: mediaSource.id,
|
MediaSourceId: mediaSource.id,
|
||||||
PlayMethod: PlayMethod.DirectPlay,
|
PlayMethod: mediaSource.playMethod,
|
||||||
PlaySessionId: playsessionId,
|
PlaySessionId: playsessionId,
|
||||||
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
||||||
PositionTicks: userDataLastPlayedPositionTicks,
|
PositionTicks: userDataLastPlayedPositionTicks,
|
||||||
@@ -290,7 +290,7 @@ export function VideoPlayer() {
|
|||||||
IsPaused: !isPlayerPlaying,
|
IsPaused: !isPlayerPlaying,
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
MediaSourceId: mediaSource.id,
|
MediaSourceId: mediaSource.id,
|
||||||
PlayMethod: PlayMethod.DirectPlay,
|
PlayMethod: mediaSource.playMethod,
|
||||||
PlaySessionId: playsessionId,
|
PlaySessionId: playsessionId,
|
||||||
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
||||||
PositionTicks: ticks,
|
PositionTicks: ticks,
|
||||||
@@ -310,6 +310,45 @@ export function VideoPlayer() {
|
|||||||
volume,
|
volume,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const handlePause = useCallback(async () => {
|
||||||
|
if (!api) {
|
||||||
|
console.warn("API is not available, cannot report playback paused.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let currentTime = 0;
|
||||||
|
if (player.current) {
|
||||||
|
currentTime = player.current.currentTime ?? 0;
|
||||||
|
}
|
||||||
|
// Report Jellyfin server: Playback has been paused
|
||||||
|
|
||||||
|
getPlaystateApi(api).reportPlaybackProgress({
|
||||||
|
playbackProgressInfo: {
|
||||||
|
AudioStreamIndex: mediaSource.audioTrack,
|
||||||
|
CanSeek: true,
|
||||||
|
IsMuted: isPlayerMuted,
|
||||||
|
IsPaused: true,
|
||||||
|
ItemId: itemId,
|
||||||
|
MediaSourceId: mediaSource.id,
|
||||||
|
PlayMethod: mediaSource.playMethod,
|
||||||
|
PlaySessionId: playsessionId,
|
||||||
|
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
||||||
|
PositionTicks: secToTicks(currentTime),
|
||||||
|
RepeatMode: RepeatMode.RepeatNone,
|
||||||
|
VolumeLevel: Math.floor(volume * 100),
|
||||||
|
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [setCurrentTime,
|
||||||
|
api,
|
||||||
|
mediaSource,
|
||||||
|
isPlayerMuted,
|
||||||
|
isPlayerPlaying,
|
||||||
|
itemId,
|
||||||
|
playsessionId,
|
||||||
|
userDataLastPlayedPositionTicks,
|
||||||
|
volume,]);
|
||||||
|
|
||||||
|
|
||||||
const handleExitPlayer = useCallback(async () => {
|
const handleExitPlayer = useCallback(async () => {
|
||||||
appWindow.getCurrent().setFullscreen(false);
|
appWindow.getCurrent().setFullscreen(false);
|
||||||
|
|
||||||
@@ -587,6 +626,8 @@ export function VideoPlayer() {
|
|||||||
ref={player}
|
ref={player}
|
||||||
onReady={handleReady}
|
onReady={handleReady}
|
||||||
onTimeUpdate={handleTimeUpdate}
|
onTimeUpdate={handleTimeUpdate}
|
||||||
|
onPause={handlePause}
|
||||||
|
onPlay={handleTimeUpdate}
|
||||||
onError={handleError}
|
onError={handleError}
|
||||||
onEnded={handlePlaybackEnded}
|
onEnded={handlePlaybackEnded}
|
||||||
width="100vw"
|
width="100vw"
|
||||||
|
|||||||
@@ -314,9 +314,6 @@ function SeriesTitlePage() {
|
|||||||
<PlayButton
|
<PlayButton
|
||||||
item={item.data}
|
item={item.data}
|
||||||
itemType={BaseItemKind.Series}
|
itemType={BaseItemKind.Series}
|
||||||
currentAudioTrack={0}
|
|
||||||
currentVideoTrack={0}
|
|
||||||
currentSubTrack="nosub"
|
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
fullWidth: true,
|
fullWidth: true,
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ function getDeviceProfile(videoTestElement: HTMLVideoElement): DeviceProfile {
|
|||||||
TranscodingProfiles: getTranscodingProfiles(videoTestElement),
|
TranscodingProfiles: getTranscodingProfiles(videoTestElement),
|
||||||
ContainerProfiles: [],
|
ContainerProfiles: [],
|
||||||
CodecProfiles: getCodecProfiles(videoTestElement),
|
CodecProfiles: getCodecProfiles(videoTestElement),
|
||||||
SubtitleProfiles: getSubtitleProfiles(),
|
SubtitleProfiles: getSubtitleProfiles(),
|
||||||
|
//@ts-expect-error
|
||||||
ResponseProfiles: getResponseProfiles()
|
ResponseProfiles: getResponseProfiles()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type {
|
|||||||
BaseItemDto,
|
BaseItemDto,
|
||||||
MediaSegmentDtoQueryResult,
|
MediaSegmentDtoQueryResult,
|
||||||
MediaStream,
|
MediaStream,
|
||||||
|
PlayMethod,
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||||
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
||||||
@@ -31,7 +32,7 @@ type PlaybackStoreState = {
|
|||||||
bitrate?: number;
|
bitrate?: number;
|
||||||
videoCodec?: string;
|
videoCodec?: string;
|
||||||
audioCodec?: string;
|
audioCodec?: string;
|
||||||
isDirectPlay?: boolean;
|
playMethod?: PlayMethod;
|
||||||
transcodingUrl?: string;
|
transcodingUrl?: string;
|
||||||
};
|
};
|
||||||
playbackStream: string;
|
playbackStream: string;
|
||||||
@@ -416,7 +417,7 @@ export const usePlaybackStore = create<
|
|||||||
bitrate?: number,
|
bitrate?: number,
|
||||||
videoCodec?: string,
|
videoCodec?: string,
|
||||||
audioCodec?: string,
|
audioCodec?: string,
|
||||||
isDirectPlay?: boolean,
|
playMethod?: PlayMethod,
|
||||||
transcodingUrl?: string,
|
transcodingUrl?: string,
|
||||||
) =>
|
) =>
|
||||||
set((state) => {
|
set((state) => {
|
||||||
@@ -429,7 +430,7 @@ export const usePlaybackStore = create<
|
|||||||
state.mediaSource.bitrate = bitrate;
|
state.mediaSource.bitrate = bitrate;
|
||||||
state.mediaSource.videoCodec = videoCodec;
|
state.mediaSource.videoCodec = videoCodec;
|
||||||
state.mediaSource.audioCodec = audioCodec;
|
state.mediaSource.audioCodec = audioCodec;
|
||||||
state.mediaSource.isDirectPlay = isDirectPlay;
|
state.mediaSource.playMethod = playMethod;
|
||||||
state.mediaSource.transcodingUrl = transcodingUrl;
|
state.mediaSource.transcodingUrl = transcodingUrl;
|
||||||
}),
|
}),
|
||||||
setPlaybackStream: (playbackStream: string) =>
|
setPlaybackStream: (playbackStream: string) =>
|
||||||
@@ -802,9 +803,17 @@ export const playItemFromQueue = async (
|
|||||||
deviceId: api.deviceInfo.id,
|
deviceId: api.deviceInfo.id,
|
||||||
api_key: api.accessToken,
|
api_key: api.accessToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let playMethod = PlayMethod.Transcode;
|
||||||
|
if (source.SupportsDirectPlay) {
|
||||||
|
playMethod = PlayMethod.DirectPlay;
|
||||||
|
} else if (source.SupportsDirectStream) {
|
||||||
|
playMethod = PlayMethod.DirectStream;
|
||||||
|
}
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||||
let playbackUrl = `${api.basePath}/Videos/${source.Id}/stream.${source.Container}?${urlParams}`;
|
let playbackUrl = `${api.basePath}/Videos/${source.Id}/stream.${source.Container}?${urlParams}`;
|
||||||
if (source.SupportsTranscoding && source.TranscodingUrl) {
|
if (playMethod === PlayMethod.Transcode && source.TranscodingUrl) {
|
||||||
playbackUrl = `${api.basePath}${source.TranscodingUrl}`;
|
playbackUrl = `${api.basePath}${source.TranscodingUrl}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -812,8 +821,6 @@ export const playItemFromQueue = async (
|
|||||||
(value) => value.Type === "Video",
|
(value) => value.Type === "Video",
|
||||||
);
|
);
|
||||||
|
|
||||||
const isDirectPlay = !source.SupportsTranscoding || !source.TranscodingUrl;
|
|
||||||
|
|
||||||
playItem({
|
playItem({
|
||||||
metadata: {
|
metadata: {
|
||||||
itemName,
|
itemName,
|
||||||
@@ -843,7 +850,7 @@ export const playItemFromQueue = async (
|
|||||||
bitrate: source.Bitrate,
|
bitrate: source.Bitrate,
|
||||||
videoCodec: videoTrack?.[0]?.Codec,
|
videoCodec: videoTrack?.[0]?.Codec,
|
||||||
audioCodec: audio.allTracks?.find((t) => t.Index === audio.track)?.Codec,
|
audioCodec: audio.allTracks?.find((t) => t.Index === audio.track)?.Codec,
|
||||||
isDirectPlay: isDirectPlay,
|
playMethod: playMethod,
|
||||||
transcodingUrl: source.TranscodingUrl,
|
transcodingUrl: source.TranscodingUrl,
|
||||||
},
|
},
|
||||||
playbackStream: playbackUrl,
|
playbackStream: playbackUrl,
|
||||||
|
|||||||
Reference in new issue
Block a user