mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-05-28 01:28:27 +01:00
Closes #1312 Fixes #883 Adds a unified segment skip feature using the Jellyfin 10.11+ MediaSegments API. Replaces the legacy intro-only and credits-only hooks with a single useSegmentSkipper hook covering Intro, Outro, Recap, Commercial, and Preview. Three modes per segment type: none, ask (show button), auto (skip automatically). A dedicated submenu under Playback Controls keeps the main settings page uncluttered. Highlights: - utils/segments.ts uses getMediaSegmentsApi from @jellyfin/sdk so includeSegmentTypes is serialized as repeated keys instead of the bracket-encoded form axios produces by default (the Jellyfin server silently ignored the filter otherwise). Falls back to the pre-10.11 intro-skipper / chapter-credits plugin endpoints when the new API is unavailable. - hooks/useSegmentSkipper.ts stores seek and haptic in refs so the auto-skip effect does not re-run when their identities change (useHaptic returns a fresh no-op every render when disabled). currentSegment is memoized; the per-segment-type setting lookup uses a small map instead of a switch IIFE. - components/video-player/controls/Controls.tsx prioritizes Commercial > Recap > Intro > Preview > Outro when multiple segments overlap and exposes the active type to BottomControls via skipButtonText. - components/video-player/controls/BottomControls.tsx accepts the dynamic skipButtonText/skipCreditButtonText props. - providers/Downloads/types.ts extends DownloadedItem with the three new segment buckets for offline playback. - utils/atoms/settings.ts adds SegmentSkipMode and the five skip settings, defaulting to "ask". - app/(auth)/(tabs)/(home)/settings/segment-skip/page.tsx renders the five dropdowns from a data table. - translations/en.json and translations/fr.json add the new keys.
282 lines
9.4 KiB
TypeScript
282 lines
9.4 KiB
TypeScript
import { Ionicons } from "@expo/vector-icons";
|
|
import { TFunction } from "i18next";
|
|
import type React from "react";
|
|
import { useMemo } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Switch, View } from "react-native";
|
|
import { BITRATES } from "@/components/BitrateSelector";
|
|
import { PlatformDropdown } from "@/components/PlatformDropdown";
|
|
import { PLAYBACK_SPEEDS } from "@/components/PlaybackSpeedSelector";
|
|
import DisabledSetting from "@/components/settings/DisabledSetting";
|
|
import useRouter from "@/hooks/useAppRouter";
|
|
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
|
|
import { ScreenOrientationEnum, useSettings } from "@/utils/atoms/settings";
|
|
import { Text } from "../common/Text";
|
|
import { ListGroup } from "../list/ListGroup";
|
|
import { ListItem } from "../list/ListItem";
|
|
|
|
export const PlaybackControlsSettings: React.FC = () => {
|
|
const router = useRouter();
|
|
const { settings, updateSettings, pluginSettings } = useSettings();
|
|
const { t } = useTranslation();
|
|
|
|
const disabled = useMemo(
|
|
() =>
|
|
pluginSettings?.defaultVideoOrientation?.locked === true &&
|
|
pluginSettings?.safeAreaInControlsEnabled?.locked === true &&
|
|
pluginSettings?.disableHapticFeedback?.locked === true,
|
|
[pluginSettings],
|
|
);
|
|
|
|
const orientations = [
|
|
ScreenOrientation.OrientationLock.DEFAULT,
|
|
ScreenOrientation.OrientationLock.PORTRAIT_UP,
|
|
ScreenOrientation.OrientationLock.LANDSCAPE,
|
|
ScreenOrientation.OrientationLock.LANDSCAPE_LEFT,
|
|
ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT,
|
|
];
|
|
|
|
const orientationTranslations = useMemo(
|
|
() => ({
|
|
[ScreenOrientation.OrientationLock.DEFAULT]:
|
|
"home.settings.other.orientations.DEFAULT",
|
|
[ScreenOrientation.OrientationLock.PORTRAIT_UP]:
|
|
"home.settings.other.orientations.PORTRAIT_UP",
|
|
[ScreenOrientation.OrientationLock.LANDSCAPE]:
|
|
"home.settings.other.orientations.LANDSCAPE",
|
|
[ScreenOrientation.OrientationLock.LANDSCAPE_LEFT]:
|
|
"home.settings.other.orientations.LANDSCAPE_LEFT",
|
|
[ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT]:
|
|
"home.settings.other.orientations.LANDSCAPE_RIGHT",
|
|
}),
|
|
[],
|
|
);
|
|
|
|
const orientationOptions = useMemo(
|
|
() => [
|
|
{
|
|
options: orientations.map((orientation) => ({
|
|
type: "radio" as const,
|
|
label: t(ScreenOrientationEnum[orientation]),
|
|
value: String(orientation),
|
|
selected: orientation === settings?.defaultVideoOrientation,
|
|
onPress: () =>
|
|
updateSettings({ defaultVideoOrientation: orientation }),
|
|
})),
|
|
},
|
|
],
|
|
[orientations, settings?.defaultVideoOrientation, t, updateSettings],
|
|
);
|
|
|
|
const bitrateOptions = useMemo(
|
|
() => [
|
|
{
|
|
options: BITRATES.map((bitrate) => ({
|
|
type: "radio" as const,
|
|
label: bitrate.key,
|
|
value: bitrate.key,
|
|
selected: bitrate.key === settings?.defaultBitrate?.key,
|
|
onPress: () => updateSettings({ defaultBitrate: bitrate }),
|
|
})),
|
|
},
|
|
],
|
|
[settings?.defaultBitrate?.key, updateSettings],
|
|
);
|
|
|
|
const autoPlayEpisodeOptions = useMemo(
|
|
() => [
|
|
{
|
|
options: AUTOPLAY_EPISODES_COUNT(t).map((item) => ({
|
|
type: "radio" as const,
|
|
label: item.key,
|
|
value: item.key,
|
|
selected: item.key === settings?.maxAutoPlayEpisodeCount?.key,
|
|
onPress: () => updateSettings({ maxAutoPlayEpisodeCount: item }),
|
|
})),
|
|
},
|
|
],
|
|
[settings?.maxAutoPlayEpisodeCount?.key, t, updateSettings],
|
|
);
|
|
|
|
const playbackSpeedOptions = useMemo(
|
|
() => [
|
|
{
|
|
options: PLAYBACK_SPEEDS.map((speed) => ({
|
|
type: "radio" as const,
|
|
label: speed.label,
|
|
value: speed.value,
|
|
selected: speed.value === settings?.defaultPlaybackSpeed,
|
|
onPress: () => updateSettings({ defaultPlaybackSpeed: speed.value }),
|
|
})),
|
|
},
|
|
],
|
|
[settings?.defaultPlaybackSpeed, updateSettings],
|
|
);
|
|
|
|
if (!settings) return null;
|
|
|
|
return (
|
|
<DisabledSetting disabled={disabled}>
|
|
<ListGroup title={t("home.settings.other.other_title")} className=''>
|
|
<ListItem
|
|
title={t("home.settings.other.video_orientation")}
|
|
disabled={pluginSettings?.defaultVideoOrientation?.locked}
|
|
>
|
|
<PlatformDropdown
|
|
groups={orientationOptions}
|
|
trigger={
|
|
<View className='flex flex-row items-center justify-between py-1.5 pl-3'>
|
|
<Text className='mr-1 text-[#8E8D91]'>
|
|
{t(
|
|
orientationTranslations[
|
|
settings.defaultVideoOrientation as keyof typeof orientationTranslations
|
|
],
|
|
) || "Unknown Orientation"}
|
|
</Text>
|
|
<Ionicons
|
|
name='chevron-expand-sharp'
|
|
size={18}
|
|
color='#5A5960'
|
|
/>
|
|
</View>
|
|
}
|
|
title={t("home.settings.other.orientation")}
|
|
/>
|
|
</ListItem>
|
|
|
|
<ListItem
|
|
title={t("home.settings.other.safe_area_in_controls")}
|
|
disabled={pluginSettings?.safeAreaInControlsEnabled?.locked}
|
|
>
|
|
<Switch
|
|
value={settings.safeAreaInControlsEnabled}
|
|
disabled={pluginSettings?.safeAreaInControlsEnabled?.locked}
|
|
onValueChange={(value) =>
|
|
updateSettings({ safeAreaInControlsEnabled: value })
|
|
}
|
|
/>
|
|
</ListItem>
|
|
|
|
<ListItem
|
|
title={t("home.settings.other.default_quality")}
|
|
disabled={pluginSettings?.defaultBitrate?.locked}
|
|
>
|
|
<PlatformDropdown
|
|
groups={bitrateOptions}
|
|
trigger={
|
|
<View className='flex flex-row items-center justify-between pl-3 py-1.5 '>
|
|
<Text className='mr-1 text-[#8E8D91]'>
|
|
{settings.defaultBitrate?.key}
|
|
</Text>
|
|
<Ionicons
|
|
name='chevron-expand-sharp'
|
|
size={18}
|
|
color='#5A5960'
|
|
/>
|
|
</View>
|
|
}
|
|
title={t("home.settings.other.default_quality")}
|
|
/>
|
|
</ListItem>
|
|
|
|
<ListItem
|
|
title={t("home.settings.other.default_playback_speed")}
|
|
disabled={pluginSettings?.defaultPlaybackSpeed?.locked}
|
|
>
|
|
<PlatformDropdown
|
|
groups={playbackSpeedOptions}
|
|
trigger={
|
|
<View className='flex flex-row items-center justify-between pl-3 py-1.5'>
|
|
<Text className='mr-1 text-[#8E8D91]'>
|
|
{PLAYBACK_SPEEDS.find(
|
|
(s) => s.value === settings.defaultPlaybackSpeed,
|
|
)?.label ?? "1x"}
|
|
</Text>
|
|
<Ionicons
|
|
name='chevron-expand-sharp'
|
|
size={18}
|
|
color='#5A5960'
|
|
/>
|
|
</View>
|
|
}
|
|
title={t("home.settings.other.default_playback_speed")}
|
|
/>
|
|
</ListItem>
|
|
|
|
<ListItem
|
|
title={t("home.settings.other.disable_haptic_feedback")}
|
|
disabled={pluginSettings?.disableHapticFeedback?.locked}
|
|
>
|
|
<Switch
|
|
value={settings.disableHapticFeedback}
|
|
disabled={pluginSettings?.disableHapticFeedback?.locked}
|
|
onValueChange={(disableHapticFeedback) =>
|
|
updateSettings({ disableHapticFeedback })
|
|
}
|
|
/>
|
|
</ListItem>
|
|
|
|
<ListItem
|
|
title={t("home.settings.other.auto_play_next_episode")}
|
|
disabled={pluginSettings?.autoPlayNextEpisode?.locked}
|
|
>
|
|
<Switch
|
|
value={settings.autoPlayNextEpisode}
|
|
disabled={pluginSettings?.autoPlayNextEpisode?.locked}
|
|
onValueChange={(autoPlayNextEpisode) =>
|
|
updateSettings({ autoPlayNextEpisode })
|
|
}
|
|
/>
|
|
</ListItem>
|
|
|
|
<ListItem
|
|
title={t("home.settings.other.max_auto_play_episode_count")}
|
|
disabled={!settings.autoPlayNextEpisode}
|
|
>
|
|
<PlatformDropdown
|
|
groups={autoPlayEpisodeOptions}
|
|
trigger={
|
|
<View className='flex flex-row items-center justify-between py-1.5 pl-3'>
|
|
<Text className='mr-1 text-[#8E8D91]'>
|
|
{t(settings?.maxAutoPlayEpisodeCount.key)}
|
|
</Text>
|
|
<Ionicons
|
|
name='chevron-expand-sharp'
|
|
size={18}
|
|
color='#5A5960'
|
|
/>
|
|
</View>
|
|
}
|
|
title={t("home.settings.other.max_auto_play_episode_count")}
|
|
/>
|
|
</ListItem>
|
|
|
|
{/* Media Segment Skip Settings */}
|
|
<ListItem
|
|
title={t("home.settings.other.segment_skip_settings")}
|
|
subtitle={t("home.settings.other.segment_skip_settings_description")}
|
|
onPress={() => router.push("/settings/segment-skip/page")}
|
|
>
|
|
<Ionicons name='chevron-forward' size={20} color='#8E8D91' />
|
|
</ListItem>
|
|
</ListGroup>
|
|
</DisabledSetting>
|
|
);
|
|
};
|
|
|
|
const AUTOPLAY_EPISODES_COUNT = (
|
|
t: TFunction<"translation", undefined>,
|
|
): {
|
|
key: string;
|
|
value: number;
|
|
}[] => [
|
|
{ key: t("home.settings.other.disabled"), value: -1 },
|
|
{ key: "1", value: 1 },
|
|
{ key: "2", value: 2 },
|
|
{ key: "3", value: 3 },
|
|
{ key: "4", value: 4 },
|
|
{ key: "5", value: 5 },
|
|
{ key: "6", value: 6 },
|
|
{ key: "7", value: 7 },
|
|
];
|