fix: can't play local media bug

appeared after playback rewrite
This commit is contained in:
Fredrik Burmester
2024-08-21 23:21:53 +02:00
parent e216c8392f
commit b1062628d9
7 changed files with 22 additions and 77 deletions

View File

@@ -18,7 +18,7 @@ interface Props extends React.ComponentProps<typeof Button> {
export const PlayButton: React.FC<Props> = ({ item, url, ...props }) => {
const { showActionSheetWithOptions } = useActionSheet();
const client = useRemoteMediaClient();
const { currentlyPlaying, setCurrentlyPlayingState } = usePlayback();
const { setCurrentlyPlayingState } = usePlayback();
const onPress = async () => {
if (!url || !item) return;

View File

@@ -9,11 +9,7 @@ import { useAtom } from "jotai";
import { Text } from "../common/Text";
import { useFiles } from "@/hooks/useFiles";
import { useSettings } from "@/utils/atoms/settings";
import {
currentlyPlayingItemAtom,
fullScreenAtom,
playingAtom,
} from "@/utils/atoms/playState";
import { usePlayback } from "@/providers/PlaybackProvider";
interface EpisodeCardProps {
item: BaseItemDto;
@@ -26,23 +22,15 @@ interface EpisodeCardProps {
*/
export const EpisodeCard: React.FC<EpisodeCardProps> = ({ item }) => {
const { deleteFile } = useFiles();
const [, setCurrentlyPlaying] = useAtom(currentlyPlayingItemAtom);
const [, setPlaying] = useAtom(playingAtom);
const [, setFullscreen] = useAtom(fullScreenAtom);
const [settings] = useSettings();
/**
* Handles opening the file for playback.
*/
const { setCurrentlyPlayingState } = usePlayback();
const handleOpenFile = useCallback(async () => {
setCurrentlyPlaying({
setCurrentlyPlayingState({
item,
playbackUrl: `${FileSystem.documentDirectory}/${item.Id}.mp4`,
url: `${FileSystem.documentDirectory}/${item.Id}.mp4`,
});
setPlaying(true);
if (settings?.openFullScreenVideoPlayerByDefault === true)
setFullscreen(true);
}, [item, setCurrentlyPlaying, settings]);
}, [item, setCurrentlyPlayingState]);
/**
* Handles deleting the file with haptic feedback.

View File

@@ -11,11 +11,7 @@ import { useFiles } from "@/hooks/useFiles";
import { runtimeTicksToMinutes } from "@/utils/time";
import { useSettings } from "@/utils/atoms/settings";
import {
currentlyPlayingItemAtom,
playingAtom,
fullScreenAtom,
} from "@/utils/atoms/playState";
import { usePlayback } from "@/providers/PlaybackProvider";
interface MovieCardProps {
item: BaseItemDto;
@@ -28,25 +24,16 @@ interface MovieCardProps {
*/
export const MovieCard: React.FC<MovieCardProps> = ({ item }) => {
const { deleteFile } = useFiles();
const [, setCurrentlyPlaying] = useAtom(currentlyPlayingItemAtom);
const [, setPlaying] = useAtom(playingAtom);
const [, setFullscreen] = useAtom(fullScreenAtom);
const [settings] = useSettings();
/**
* Handles opening the file for playback.
*/
const { setCurrentlyPlayingState } = usePlayback();
const handleOpenFile = useCallback(() => {
console.log("Open movie file", item.Name);
setCurrentlyPlaying({
setCurrentlyPlayingState({
item,
playbackUrl: `${FileSystem.documentDirectory}/${item.Id}.mp4`,
url: `${FileSystem.documentDirectory}/${item.Id}.mp4`,
});
setPlaying(true);
if (settings?.openFullScreenVideoPlayerByDefault === true) {
setFullscreen(true);
}
}, [item, setCurrentlyPlaying, setPlaying, settings]);
}, [item, setCurrentlyPlayingState]);
/**
* Handles deleting the file with haptic feedback.