mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-21 18:48:19 +00:00
Compare commits
2 Commits
feat/tv-in
...
refactor-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1176905cb7 | ||
|
|
358e00d8b7 |
@@ -1,5 +1,8 @@
|
|||||||
import { Feather } from "@expo/vector-icons";
|
import { Feather } from "@expo/vector-icons";
|
||||||
import { useCallback, useEffect } from "react";
|
import type { PlaybackProgressInfo } from "@jellyfin/sdk/lib/generated-client/models";
|
||||||
|
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api";
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
|
import { useCallback, useEffect, useRef } from "react";
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
import { Pressable } from "react-native-gesture-handler";
|
import { Pressable } from "react-native-gesture-handler";
|
||||||
import GoogleCast, {
|
import GoogleCast, {
|
||||||
@@ -10,6 +13,7 @@ import GoogleCast, {
|
|||||||
useMediaStatus,
|
useMediaStatus,
|
||||||
useRemoteMediaClient,
|
useRemoteMediaClient,
|
||||||
} from "react-native-google-cast";
|
} from "react-native-google-cast";
|
||||||
|
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||||
import { RoundButton } from "./RoundButton";
|
import { RoundButton } from "./RoundButton";
|
||||||
|
|
||||||
export function Chromecast({
|
export function Chromecast({
|
||||||
@@ -24,6 +28,10 @@ export function Chromecast({
|
|||||||
const sessionManager = GoogleCast.getSessionManager();
|
const sessionManager = GoogleCast.getSessionManager();
|
||||||
const discoveryManager = GoogleCast.getDiscoveryManager();
|
const discoveryManager = GoogleCast.getDiscoveryManager();
|
||||||
const mediaStatus = useMediaStatus();
|
const mediaStatus = useMediaStatus();
|
||||||
|
const api = useAtomValue(apiAtom);
|
||||||
|
const user = useAtomValue(userAtom);
|
||||||
|
|
||||||
|
const lastReportedProgressRef = useRef(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -36,6 +44,53 @@ export function Chromecast({
|
|||||||
})();
|
})();
|
||||||
}, [client, devices, castDevice, sessionManager, discoveryManager]);
|
}, [client, devices, castDevice, sessionManager, discoveryManager]);
|
||||||
|
|
||||||
|
// Report video progress to Jellyfin server
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
!api ||
|
||||||
|
!user?.Id ||
|
||||||
|
!mediaStatus ||
|
||||||
|
!mediaStatus.mediaInfo?.contentId
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const streamPosition = mediaStatus.streamPosition || 0;
|
||||||
|
|
||||||
|
// Report every 10 seconds
|
||||||
|
if (Math.abs(streamPosition - lastReportedProgressRef.current) < 10) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contentId = mediaStatus.mediaInfo.contentId;
|
||||||
|
const positionTicks = Math.floor(streamPosition * 10000000);
|
||||||
|
const isPaused = mediaStatus.playerState === "paused";
|
||||||
|
const streamUrl = mediaStatus.mediaInfo.contentUrl || "";
|
||||||
|
const isTranscoding = streamUrl.includes("m3u8");
|
||||||
|
|
||||||
|
const progressInfo: PlaybackProgressInfo = {
|
||||||
|
ItemId: contentId,
|
||||||
|
PositionTicks: positionTicks,
|
||||||
|
IsPaused: isPaused,
|
||||||
|
PlayMethod: isTranscoding ? "Transcode" : "DirectStream",
|
||||||
|
PlaySessionId: contentId,
|
||||||
|
};
|
||||||
|
|
||||||
|
getPlaystateApi(api)
|
||||||
|
.reportPlaybackProgress({ playbackProgressInfo: progressInfo })
|
||||||
|
.then(() => {
|
||||||
|
lastReportedProgressRef.current = streamPosition;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Failed to report Chromecast progress:", error);
|
||||||
|
});
|
||||||
|
}, [
|
||||||
|
api,
|
||||||
|
user?.Id,
|
||||||
|
mediaStatus?.streamPosition,
|
||||||
|
mediaStatus?.mediaInfo?.contentId,
|
||||||
|
]);
|
||||||
|
|
||||||
// Android requires the cast button to be present for startDiscovery to work
|
// Android requires the cast button to be present for startDiscovery to work
|
||||||
const AndroidCastButton = useCallback(
|
const AndroidCastButton = useCallback(
|
||||||
() =>
|
() =>
|
||||||
|
|||||||
@@ -167,16 +167,17 @@ final class MPVLayerRenderer {
|
|||||||
// Use AVFoundation video output - required for PiP support
|
// Use AVFoundation video output - required for PiP support
|
||||||
checkError(mpv_set_option_string(handle, "vo", "avfoundation"))
|
checkError(mpv_set_option_string(handle, "vo", "avfoundation"))
|
||||||
|
|
||||||
|
// Enable composite OSD mode - renders subtitles directly onto video frames using GPU
|
||||||
|
// This is better for PiP as subtitles are baked into the video
|
||||||
|
// NOTE: Must be set BEFORE the #if targetEnvironment check or tvOS will freeze on player exit
|
||||||
|
checkError(mpv_set_option_string(handle, "avfoundation-composite-osd", "yes"))
|
||||||
|
|
||||||
// Hardware decoding with VideoToolbox
|
// Hardware decoding with VideoToolbox
|
||||||
// On simulator, use software decoding since VideoToolbox is not available
|
// On simulator, use software decoding since VideoToolbox is not available
|
||||||
// On device, use VideoToolbox with software fallback enabled
|
// On device, use VideoToolbox with software fallback enabled
|
||||||
#if targetEnvironment(simulator)
|
#if targetEnvironment(simulator)
|
||||||
checkError(mpv_set_option_string(handle, "hwdec", "no"))
|
checkError(mpv_set_option_string(handle, "hwdec", "no"))
|
||||||
#else
|
#else
|
||||||
// Only enable composite OSD mode on real device (OSD is not supported in simulator).
|
|
||||||
// This renders subtitles directly onto video frames using the GPU, which is better for PiP since subtitles are baked into the video.
|
|
||||||
checkError(mpv_set_option_string(handle, "avfoundation-composite-osd", "yes"))
|
|
||||||
|
|
||||||
checkError(mpv_set_option_string(handle, "hwdec", "videotoolbox"))
|
checkError(mpv_set_option_string(handle, "hwdec", "videotoolbox"))
|
||||||
#endif
|
#endif
|
||||||
checkError(mpv_set_option_string(handle, "hwdec-codecs", "all"))
|
checkError(mpv_set_option_string(handle, "hwdec-codecs", "all"))
|
||||||
|
|||||||
Reference in New Issue
Block a user