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 {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
PlayMethod,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||
import type { SxProps } from "@mui/material";
|
||||
@@ -229,8 +230,17 @@ const PlayButton = ({
|
||||
};
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
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 (
|
||||
result?.mediaSource.MediaSources?.[0].SupportsTranscoding &&
|
||||
playMethod === PlayMethod.Transcode &&
|
||||
result?.mediaSource.MediaSources?.[0].TranscodingUrl
|
||||
) {
|
||||
playbackUrl = `${api.basePath}${result.mediaSource.MediaSources[0].TranscodingUrl}`;
|
||||
@@ -248,10 +258,6 @@ const PlayButton = ({
|
||||
(value) => value.Type === "Video",
|
||||
);
|
||||
|
||||
const isDirectPlay =
|
||||
!result.mediaSource.MediaSources?.[0].SupportsTranscoding ||
|
||||
!result.mediaSource.MediaSources?.[0].TranscodingUrl;
|
||||
|
||||
playItem({
|
||||
metadata: {
|
||||
itemName: itemName ?? "",
|
||||
@@ -283,7 +289,7 @@ const PlayButton = ({
|
||||
audioCodec:
|
||||
audio.allTracks?.find((t) => t.Index === audio.track)?.Codec ??
|
||||
"",
|
||||
isDirectPlay: isDirectPlay,
|
||||
playMethod: playMethod,
|
||||
transcodingUrl:
|
||||
result.mediaSource.MediaSources?.[0].TranscodingUrl ?? "",
|
||||
},
|
||||
|
||||
@@ -137,7 +137,7 @@ const StatsForNerds = ({ playerRef }: StatsForNerdsProps) => {
|
||||
<span>Media Source ID:</span> <span>{mediaSourceId}</span>
|
||||
<span>Play Session ID:</span> <span>{playsessionId}</span>
|
||||
<span>Playback Method:</span>{" "}
|
||||
<span>{mediaSource.isDirectPlay ? "Direct Play" : "Transcoding"}</span>
|
||||
<span>{mediaSource.playMethod}</span>
|
||||
<span>Container:</span> <span>{mediaSource.container}</span>
|
||||
<span>Video Codec:</span> <span>{mediaSource.videoCodec}</span>
|
||||
<span>Audio Codec:</span> <span>{mediaSource.audioCodec}</span>
|
||||
|
||||
@@ -147,9 +147,6 @@ function BoxSetTitlePage() {
|
||||
<PlayButton
|
||||
item={item.data}
|
||||
itemType={item.data.Type ?? "BoxSet"}
|
||||
currentVideoTrack={0}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack={0}
|
||||
userId={user?.Id}
|
||||
buttonProps={{
|
||||
fullWidth: true,
|
||||
|
||||
@@ -247,7 +247,7 @@ export function VideoPlayer() {
|
||||
IsPaused: false,
|
||||
ItemId: itemId,
|
||||
MediaSourceId: mediaSource.id,
|
||||
PlayMethod: PlayMethod.DirectPlay,
|
||||
PlayMethod: mediaSource.playMethod,
|
||||
PlaySessionId: playsessionId,
|
||||
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
||||
PositionTicks: userDataLastPlayedPositionTicks,
|
||||
@@ -290,7 +290,7 @@ export function VideoPlayer() {
|
||||
IsPaused: !isPlayerPlaying,
|
||||
ItemId: itemId,
|
||||
MediaSourceId: mediaSource.id,
|
||||
PlayMethod: PlayMethod.DirectPlay,
|
||||
PlayMethod: mediaSource.playMethod,
|
||||
PlaySessionId: playsessionId,
|
||||
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
||||
PositionTicks: ticks,
|
||||
@@ -310,6 +310,45 @@ export function VideoPlayer() {
|
||||
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 () => {
|
||||
appWindow.getCurrent().setFullscreen(false);
|
||||
|
||||
@@ -587,6 +626,8 @@ export function VideoPlayer() {
|
||||
ref={player}
|
||||
onReady={handleReady}
|
||||
onTimeUpdate={handleTimeUpdate}
|
||||
onPause={handlePause}
|
||||
onPlay={handleTimeUpdate}
|
||||
onError={handleError}
|
||||
onEnded={handlePlaybackEnded}
|
||||
width="100vw"
|
||||
|
||||
@@ -314,9 +314,6 @@ function SeriesTitlePage() {
|
||||
<PlayButton
|
||||
item={item.data}
|
||||
itemType={BaseItemKind.Series}
|
||||
currentAudioTrack={0}
|
||||
currentVideoTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
userId={user?.Id}
|
||||
buttonProps={{
|
||||
fullWidth: true,
|
||||
|
||||
@@ -47,7 +47,8 @@ function getDeviceProfile(videoTestElement: HTMLVideoElement): DeviceProfile {
|
||||
TranscodingProfiles: getTranscodingProfiles(videoTestElement),
|
||||
ContainerProfiles: [],
|
||||
CodecProfiles: getCodecProfiles(videoTestElement),
|
||||
SubtitleProfiles: getSubtitleProfiles(),
|
||||
SubtitleProfiles: getSubtitleProfiles(),
|
||||
//@ts-expect-error
|
||||
ResponseProfiles: getResponseProfiles()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
BaseItemDto,
|
||||
MediaSegmentDtoQueryResult,
|
||||
MediaStream,
|
||||
PlayMethod,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
||||
@@ -31,7 +32,7 @@ type PlaybackStoreState = {
|
||||
bitrate?: number;
|
||||
videoCodec?: string;
|
||||
audioCodec?: string;
|
||||
isDirectPlay?: boolean;
|
||||
playMethod?: PlayMethod;
|
||||
transcodingUrl?: string;
|
||||
};
|
||||
playbackStream: string;
|
||||
@@ -416,7 +417,7 @@ export const usePlaybackStore = create<
|
||||
bitrate?: number,
|
||||
videoCodec?: string,
|
||||
audioCodec?: string,
|
||||
isDirectPlay?: boolean,
|
||||
playMethod?: PlayMethod,
|
||||
transcodingUrl?: string,
|
||||
) =>
|
||||
set((state) => {
|
||||
@@ -429,7 +430,7 @@ export const usePlaybackStore = create<
|
||||
state.mediaSource.bitrate = bitrate;
|
||||
state.mediaSource.videoCodec = videoCodec;
|
||||
state.mediaSource.audioCodec = audioCodec;
|
||||
state.mediaSource.isDirectPlay = isDirectPlay;
|
||||
state.mediaSource.playMethod = playMethod;
|
||||
state.mediaSource.transcodingUrl = transcodingUrl;
|
||||
}),
|
||||
setPlaybackStream: (playbackStream: string) =>
|
||||
@@ -802,9 +803,17 @@ export const playItemFromQueue = async (
|
||||
deviceId: api.deviceInfo.id,
|
||||
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();
|
||||
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}`;
|
||||
}
|
||||
|
||||
@@ -812,8 +821,6 @@ export const playItemFromQueue = async (
|
||||
(value) => value.Type === "Video",
|
||||
);
|
||||
|
||||
const isDirectPlay = !source.SupportsTranscoding || !source.TranscodingUrl;
|
||||
|
||||
playItem({
|
||||
metadata: {
|
||||
itemName,
|
||||
@@ -843,7 +850,7 @@ export const playItemFromQueue = async (
|
||||
bitrate: source.Bitrate,
|
||||
videoCodec: videoTrack?.[0]?.Codec,
|
||||
audioCodec: audio.allTracks?.find((t) => t.Index === audio.track)?.Codec,
|
||||
isDirectPlay: isDirectPlay,
|
||||
playMethod: playMethod,
|
||||
transcodingUrl: source.TranscodingUrl,
|
||||
},
|
||||
playbackStream: playbackUrl,
|
||||
|
||||
Reference in new issue
Block a user