fix: orientation in video player and app i general

This commit is contained in:
Fredrik Burmester
2025-02-09 11:45:32 +01:00
parent d29501386b
commit 528b4ad7ac
4 changed files with 46 additions and 22 deletions

View File

@@ -1,8 +1,28 @@
import { Stack } from "expo-router";
import React from "react";
import React, { useEffect } from "react";
import { SystemBars } from "react-native-edge-to-edge";
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
import { useSettings } from "@/utils/atoms/settings";
export default function Layout() {
const [settings] = useSettings();
useEffect(() => {
if (settings.defaultVideoOrientation) {
ScreenOrientation.lockAsync(settings.defaultVideoOrientation);
}
return () => {
if (settings.autoRotate === true) {
ScreenOrientation.unlockAsync();
} else {
ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
);
}
};
}, [settings]);
return (
<>
<SystemBars hidden />

View File

@@ -55,6 +55,7 @@ import { useTranslation } from "react-i18next";
import { useSafeAreaInsets } from "react-native-safe-area-context";
export default function page() {
console.log("Direct Player");
const videoRef = useRef<VlcPlayerViewRef>(null);
const user = useAtomValue(userAtom);
const api = useAtomValue(apiAtom);
@@ -72,7 +73,7 @@ export default function page() {
const cacheProgress = useSharedValue(0);
let getDownloadedItem = null;
if (!Platform.isTV) {
getDownloadedItem = downloadProvider.useDownload();
getDownloadedItem = downloadProvider.useDownload();
}
const revalidateProgressCache = useInvalidatePlaybackProgressCache();
@@ -303,9 +304,6 @@ export default function page() {
[item?.Id, isPlaying, api, isPlaybackStopped, audioIndex, subtitleIndex]
);
useOrientation();
useOrientationSettings();
useWebSocket({
isPlaying: isPlaying,
togglePlay: togglePlay,
@@ -386,16 +384,18 @@ export default function page() {
const allSubs =
stream?.mediaSource.MediaStreams?.filter(
(sub: { Type: string; }) => sub.Type === "Subtitle"
(sub: { Type: string }) => sub.Type === "Subtitle"
) || [];
const chosenSubtitleTrack = allSubs.find(
(sub: { Index: number; }) => sub.Index === subtitleIndex
(sub: { Index: number }) => sub.Index === subtitleIndex
);
const allAudio =
stream?.mediaSource.MediaStreams?.filter(
(audio: { Type: string; }) => audio.Type === "Audio"
(audio: { Type: string }) => audio.Type === "Audio"
) || [];
const chosenAudioTrack = allAudio.find((audio: { Index: number | undefined; }) => audio.Index === audioIndex);
const chosenAudioTrack = allAudio.find(
(audio: { Index: number | undefined }) => audio.Index === audioIndex
);
// Direct playback CASE
if (!bitrateValue) {

View File

@@ -42,6 +42,8 @@ import { SubtitleHelper } from "@/utils/SubtitleHelper";
import { useTranslation } from "react-i18next";
const Player = () => {
console.log("Transcoding Player");
const api = useAtomValue(apiAtom);
const user = useAtomValue(userAtom);
const [settings] = useSettings();
@@ -295,9 +297,6 @@ const Player = () => {
]
);
useOrientation();
useOrientationSettings();
useWebSocket({
isPlaying: isPlaying,
togglePlay: togglePlay,

View File

@@ -71,15 +71,17 @@ function useNotificationObserver() {
}
}
Notifications.getLastNotificationResponseAsync().then((response: { notification: any; }) => {
if (!isMounted || !response?.notification) {
return;
Notifications.getLastNotificationResponseAsync().then(
(response: { notification: any }) => {
if (!isMounted || !response?.notification) {
return;
}
redirect(response?.notification);
}
redirect(response?.notification);
});
);
const subscription = Notifications.addNotificationResponseReceivedListener(
(response: { notification: any; }) => {
(response: { notification: any }) => {
redirect(response.notification);
}
);
@@ -127,7 +129,7 @@ if (!Platform.isTV) {
const downloadUrl = url + "download/" + job.id;
const tasks = await BackGroundDownloader.checkForExistingDownloads();
if (tasks.find((task: { id: string; }) => task.id === job.id)) {
if (tasks.find((task: { id: string }) => task.id === job.id)) {
console.log("TaskManager ~ Download already in progress: ", job.id);
continue;
}
@@ -269,12 +271,15 @@ function Layout() {
}, []);
useEffect(() => {
if (settings?.autoRotate === true)
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.DEFAULT);
else
// If the user has auto rotate enabled, unlock the orientation
if (settings.autoRotate === true) {
ScreenOrientation.unlockAsync();
} else {
// If the user has auto rotate disabled, lock the orientation to portrait
ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
);
}
}, [settings]);
useEffect(() => {