mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-02-16 17:12:23 +00:00
fix(player): add null guards for item in play settings
This commit is contained in:
@@ -86,7 +86,7 @@ const Page: React.FC = () => {
|
||||
<View style={{ paddingHorizontal: 16, width: "100%" }}>
|
||||
<View
|
||||
style={{
|
||||
height: item?.Type === "Episode" ? 300 : 450,
|
||||
height: 450,
|
||||
}}
|
||||
className='bg-transparent rounded-lg mb-4 w-full'
|
||||
/>
|
||||
|
||||
@@ -838,23 +838,23 @@ export const ItemContentTV: React.FC<ItemContentTVProps> = React.memo(
|
||||
}, [selectedOptions?.bitrate?.key, t]);
|
||||
|
||||
// Format year and duration
|
||||
const year = item.ProductionYear;
|
||||
const duration = item.RunTimeTicks
|
||||
const year = item?.ProductionYear;
|
||||
const duration = item?.RunTimeTicks
|
||||
? runtimeTicksToMinutes(item.RunTimeTicks)
|
||||
: null;
|
||||
const hasProgress = (item.UserData?.PlaybackPositionTicks ?? 0) > 0;
|
||||
const hasProgress = (item?.UserData?.PlaybackPositionTicks ?? 0) > 0;
|
||||
const remainingTime = hasProgress
|
||||
? runtimeTicksToMinutes(
|
||||
(item.RunTimeTicks || 0) -
|
||||
(item.UserData?.PlaybackPositionTicks || 0),
|
||||
(item?.RunTimeTicks || 0) -
|
||||
(item?.UserData?.PlaybackPositionTicks || 0),
|
||||
)
|
||||
: null;
|
||||
|
||||
// Get director
|
||||
const director = item.People?.find((p) => p.Type === "Director");
|
||||
const director = item?.People?.find((p) => p.Type === "Director");
|
||||
|
||||
// Get cast (first 3)
|
||||
const cast = item.People?.filter((p) => p.Type === "Actor")?.slice(0, 3);
|
||||
const cast = item?.People?.filter((p) => p.Type === "Actor")?.slice(0, 3);
|
||||
|
||||
if (!item || !selectedOptions) return null;
|
||||
|
||||
|
||||
@@ -7,7 +7,10 @@ import { getDefaultPlaySettings } from "@/utils/jellyfin/getDefaultPlaySettings"
|
||||
* React hook wrapper for getDefaultPlaySettings.
|
||||
* Used in UI components for initial playback (no previous track state).
|
||||
*/
|
||||
const useDefaultPlaySettings = (item: BaseItemDto, settings: Settings | null) =>
|
||||
const useDefaultPlaySettings = (
|
||||
item: BaseItemDto | null | undefined,
|
||||
settings: Settings | null,
|
||||
) =>
|
||||
useMemo(() => {
|
||||
const { mediaSource, audioIndex, subtitleIndex, bitrate } =
|
||||
getDefaultPlaySettings(item, settings);
|
||||
|
||||
@@ -42,12 +42,17 @@ export interface PreviousIndexes {
|
||||
* @param previous - Optional previous track selections to carry over (for sequential play)
|
||||
*/
|
||||
export function getDefaultPlaySettings(
|
||||
item: BaseItemDto,
|
||||
item: BaseItemDto | null | undefined,
|
||||
settings: Settings | null,
|
||||
previous?: { indexes?: PreviousIndexes; source?: MediaSourceInfo },
|
||||
): PlaySettings {
|
||||
const bitrate = settings?.defaultBitrate ?? BITRATES[0];
|
||||
|
||||
// Handle undefined/null item
|
||||
if (!item) {
|
||||
return { item: {} as BaseItemDto, bitrate };
|
||||
}
|
||||
|
||||
// Live TV programs don't have media sources
|
||||
if (item.Type === "Program") {
|
||||
return { item, bitrate };
|
||||
|
||||
Reference in New Issue
Block a user