mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-05-25 16:26:54 +01:00
refactor: clean up dead code and consolidate casting utilities
- Remove dead Chromecast files (ChromecastMiniPlayer, chromecast-player) - Remove dead AirPlay files (AirPlayMiniPlayer, airplay-player, useAirPlayPlayer) - Remove duplicate AirPlay utilities (options.ts, helpers.ts) - Consolidate unique Chromecast helpers into unified casting helpers - Add formatEpisodeInfo and shouldShowNextEpisodeCountdown - Update all imports to use unified casting utilities - Fix TypeScript errors: - Use correct MediaStatus properties (playerState vs isPaused/isBuffering) - Use getPlaystateApi from Jellyfin SDK - Use setStreamVolume for RemoteMediaClient - Fix calculateEndingTime signature - Fix segment auto-skip to use proper settings (skipIntro, skipOutro, etc) - Remove unused imports - Update ChromecastSettingsMenu to use unified types from casting/types.ts
This commit is contained in:
@@ -10,7 +10,7 @@ import React from "react";
|
||||
import { FlatList, Modal, Pressable, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { truncateTitle } from "@/utils/chromecast/helpers";
|
||||
import { truncateTitle } from "@/utils/casting/helpers";
|
||||
|
||||
interface ChromecastEpisodeListProps {
|
||||
visible: boolean;
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
/**
|
||||
* Mini Chromecast player bar shown at the bottom of the screen
|
||||
* Similar to music player mini bar
|
||||
*/
|
||||
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { useRouter } from "expo-router";
|
||||
import React from "react";
|
||||
import { Pressable, View } from "react-native";
|
||||
import Animated, {
|
||||
FadeIn,
|
||||
FadeOut,
|
||||
SlideInDown,
|
||||
SlideOutDown,
|
||||
} from "react-native-reanimated";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { formatEpisodeInfo, truncateTitle } from "@/utils/chromecast/helpers";
|
||||
import { CHROMECAST_CONSTANTS } from "@/utils/chromecast/options";
|
||||
import { useChromecastPlayer } from "./hooks/useChromecastPlayer";
|
||||
|
||||
export const ChromecastMiniPlayer: React.FC = () => {
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const { playerState, currentItem, togglePlay, showNextEpisodeCountdown } =
|
||||
useChromecastPlayer();
|
||||
|
||||
// Don't show if not connected or no media
|
||||
if (!playerState.isConnected || !playerState.currentItemId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handlePress = () => {
|
||||
router.push("/chromecast-player");
|
||||
};
|
||||
|
||||
const progress =
|
||||
playerState.duration > 0
|
||||
? (playerState.progress / playerState.duration) * 100
|
||||
: 0;
|
||||
|
||||
return (
|
||||
<Animated.View
|
||||
entering={SlideInDown.duration(CHROMECAST_CONSTANTS.ANIMATION_DURATION)}
|
||||
exiting={SlideOutDown.duration(CHROMECAST_CONSTANTS.ANIMATION_DURATION)}
|
||||
style={{
|
||||
position: "absolute",
|
||||
bottom: insets.bottom,
|
||||
left: 0,
|
||||
right: 0,
|
||||
backgroundColor: "#1a1a1a",
|
||||
borderTopWidth: 1,
|
||||
borderTopColor: "#333",
|
||||
zIndex: 1000,
|
||||
}}
|
||||
>
|
||||
{/* Progress bar */}
|
||||
<View
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: 2,
|
||||
backgroundColor: "#333",
|
||||
}}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
height: 2,
|
||||
width: `${progress}%`,
|
||||
backgroundColor: "#e50914",
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<Pressable onPress={handlePress}>
|
||||
<View
|
||||
style={{
|
||||
height: CHROMECAST_CONSTANTS.MINI_PLAYER_HEIGHT,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
paddingHorizontal: 16,
|
||||
gap: 12,
|
||||
}}
|
||||
>
|
||||
{/* Cast icon */}
|
||||
<View
|
||||
style={{
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 4,
|
||||
backgroundColor: "#333",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Ionicons name='tv' size={24} color='#e50914' />
|
||||
</View>
|
||||
|
||||
{/* Media info */}
|
||||
<View style={{ flex: 1 }}>
|
||||
{currentItem && (
|
||||
<>
|
||||
<Text
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: 14,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{truncateTitle(currentItem.Name || "Unknown", 40)}
|
||||
</Text>
|
||||
<View style={{ flexDirection: "row", gap: 8 }}>
|
||||
<Text
|
||||
style={{
|
||||
color: "#999",
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
{formatEpisodeInfo(
|
||||
currentItem.ParentIndexNumber,
|
||||
currentItem.IndexNumber,
|
||||
)}
|
||||
</Text>
|
||||
{showNextEpisodeCountdown && (
|
||||
<Animated.Text
|
||||
entering={FadeIn}
|
||||
exiting={FadeOut}
|
||||
style={{
|
||||
color: "#e50914",
|
||||
fontSize: 12,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
>
|
||||
Next episode starting...
|
||||
</Animated.Text>
|
||||
)}
|
||||
</View>
|
||||
</>
|
||||
)}
|
||||
{!currentItem && (
|
||||
<>
|
||||
<Text
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: 14,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
>
|
||||
Casting to {playerState.deviceName || "Chromecast"}
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
color: "#999",
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
{playerState.isPlaying ? "Playing" : "Paused"}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Play/Pause button */}
|
||||
<Pressable
|
||||
onPress={(e) => {
|
||||
e.stopPropagation();
|
||||
togglePlay();
|
||||
}}
|
||||
style={{
|
||||
width: 48,
|
||||
height: 48,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
{playerState.isBuffering ? (
|
||||
<Ionicons name='hourglass-outline' size={24} color='white' />
|
||||
) : (
|
||||
<Ionicons
|
||||
name={playerState.isPlaying ? "pause" : "play"}
|
||||
size={28}
|
||||
color='white'
|
||||
/>
|
||||
)}
|
||||
</Pressable>
|
||||
</View>
|
||||
</Pressable>
|
||||
</Animated.View>
|
||||
);
|
||||
};
|
||||
@@ -13,7 +13,7 @@ import type {
|
||||
AudioTrack,
|
||||
MediaSource,
|
||||
SubtitleTrack,
|
||||
} from "@/utils/chromecast/options";
|
||||
} from "@/utils/casting/types";
|
||||
|
||||
interface ChromecastSettingsMenuProps {
|
||||
visible: boolean;
|
||||
@@ -39,7 +39,7 @@ const PLAYBACK_SPEEDS = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
|
||||
export const ChromecastSettingsMenu: React.FC<ChromecastSettingsMenuProps> = ({
|
||||
visible,
|
||||
onClose,
|
||||
item,
|
||||
item: _item, // Reserved for future use (technical info display)
|
||||
mediaSources,
|
||||
selectedMediaSource,
|
||||
onMediaSourceChange,
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
calculateEndingTime,
|
||||
formatTime,
|
||||
shouldShowNextEpisodeCountdown,
|
||||
} from "@/utils/chromecast/helpers";
|
||||
} from "@/utils/casting/helpers";
|
||||
import {
|
||||
CHROMECAST_CONSTANTS,
|
||||
type ChromecastPlayerState,
|
||||
@@ -187,8 +187,8 @@ export const useChromecastPlayer = () => {
|
||||
const currentTime = formatTime(playerState.progress);
|
||||
const remainingTime = formatTime(playerState.duration - playerState.progress);
|
||||
const endingTime = calculateEndingTime(
|
||||
playerState.duration - playerState.progress,
|
||||
true, // TODO: Add use24HourFormat setting
|
||||
playerState.progress,
|
||||
playerState.duration,
|
||||
);
|
||||
|
||||
// Next episode countdown
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useDownloadedFiles } from "@/providers/Downloads/downloadProvider";
|
||||
import { apiAtom } from "@/providers/JellyfinProvider";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
import { isWithinSegment } from "@/utils/chromecast/helpers";
|
||||
import { isWithinSegment } from "@/utils/casting/helpers";
|
||||
import type { ChromecastSegmentData } from "@/utils/chromecast/options";
|
||||
import { useSegments } from "@/utils/segments";
|
||||
|
||||
@@ -20,13 +19,12 @@ export const useChromecastSegments = (
|
||||
) => {
|
||||
const api = useAtomValue(apiAtom);
|
||||
const { settings } = useSettings();
|
||||
const { downloadedFiles } = useDownloadedFiles();
|
||||
|
||||
// Fetch segments from autoskip API
|
||||
const { data: segmentData } = useSegments(
|
||||
item?.Id || "",
|
||||
isOffline,
|
||||
downloadedFiles,
|
||||
undefined, // downloadedFiles parameter
|
||||
api,
|
||||
);
|
||||
|
||||
@@ -137,18 +135,26 @@ export const useChromecastSegments = (
|
||||
|
||||
switch (currentSegment.type) {
|
||||
case "intro":
|
||||
return settings?.autoSkipIntro === true;
|
||||
return settings?.skipIntro === "auto";
|
||||
case "credits":
|
||||
return settings?.autoSkipCredits === true;
|
||||
return settings?.skipOutro === "auto";
|
||||
case "recap":
|
||||
return settings?.skipRecap === "auto";
|
||||
case "commercial":
|
||||
return settings?.skipCommercial === "auto";
|
||||
case "preview":
|
||||
// These don't have settings yet, don't auto-skip
|
||||
return false;
|
||||
return settings?.skipPreview === "auto";
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}, [currentSegment, settings?.autoSkipIntro, settings?.autoSkipCredits]);
|
||||
}, [
|
||||
currentSegment,
|
||||
settings?.skipIntro,
|
||||
settings?.skipOutro,
|
||||
settings?.skipRecap,
|
||||
settings?.skipCommercial,
|
||||
settings?.skipPreview,
|
||||
]);
|
||||
|
||||
return {
|
||||
segments,
|
||||
|
||||
Reference in New Issue
Block a user