mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
Fixed issue for IOS and android
This commit is contained in:
@@ -30,8 +30,20 @@ import { useQuery } from "@tanstack/react-query";
|
|||||||
import * as Haptics from "expo-haptics";
|
import * as Haptics from "expo-haptics";
|
||||||
import { useFocusEffect, useGlobalSearchParams } from "expo-router";
|
import { useFocusEffect, useGlobalSearchParams } from "expo-router";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import React, { useCallback, useMemo, useRef, useState } from "react";
|
import React, {
|
||||||
import { Alert, BackHandler, View } from "react-native";
|
useCallback,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
useEffect,
|
||||||
|
} from "react";
|
||||||
|
import {
|
||||||
|
Alert,
|
||||||
|
BackHandler,
|
||||||
|
View,
|
||||||
|
AppState,
|
||||||
|
AppStateStatus,
|
||||||
|
} from "react-native";
|
||||||
import { useSharedValue } from "react-native-reanimated";
|
import { useSharedValue } from "react-native-reanimated";
|
||||||
import settings from "../(tabs)/(home)/settings";
|
import settings from "../(tabs)/(home)/settings";
|
||||||
import { useSettings } from "@/utils/atoms/settings";
|
import { useSettings } from "@/utils/atoms/settings";
|
||||||
@@ -359,6 +371,36 @@ export default function page() {
|
|||||||
};
|
};
|
||||||
}, [])
|
}, [])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [appState, setAppState] = useState(AppState.currentState);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleAppStateChange = (nextAppState: AppStateStatus) => {
|
||||||
|
if (appState.match(/inactive|background/) && nextAppState === "active") {
|
||||||
|
console.log("App has come to the foreground!");
|
||||||
|
// Handle app coming to the foreground
|
||||||
|
} else if (nextAppState.match(/inactive|background/)) {
|
||||||
|
console.log("App has gone to the background!");
|
||||||
|
// Handle app going to the background
|
||||||
|
if (videoRef.current && videoRef.current.pause) {
|
||||||
|
videoRef.current.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setAppState(nextAppState);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use AppState.addEventListener and return a cleanup function
|
||||||
|
const subscription = AppState.addEventListener(
|
||||||
|
"change",
|
||||||
|
handleAppStateChange
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
// Cleanup the event listener when the component is unmounted
|
||||||
|
subscription.remove();
|
||||||
|
};
|
||||||
|
}, [appState]);
|
||||||
|
|
||||||
// Preselection of audio and subtitle tracks.
|
// Preselection of audio and subtitle tracks.
|
||||||
|
|
||||||
if (!settings) return null;
|
if (!settings) return null;
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ public class VlcPlayerModule: Module {
|
|||||||
Name("VlcPlayer")
|
Name("VlcPlayer")
|
||||||
View(VlcPlayerView.self) {
|
View(VlcPlayerView.self) {
|
||||||
Prop("source") { (view: VlcPlayerView, source: [String: Any]) in
|
Prop("source") { (view: VlcPlayerView, source: [String: Any]) in
|
||||||
|
if !view.hasSource {
|
||||||
view.setSource(source)
|
view.setSource(source)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Prop("paused") { (view: VlcPlayerView, paused: Bool) in
|
Prop("paused") { (view: VlcPlayerView, paused: Bool) in
|
||||||
if paused {
|
if paused {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class VlcPlayerView: ExpoView {
|
|||||||
private var externalTrack: [String: String]?
|
private var externalTrack: [String: String]?
|
||||||
private var progressTimer: DispatchSourceTimer?
|
private var progressTimer: DispatchSourceTimer?
|
||||||
private var isStopping: Bool = false // Define isStopping here
|
private var isStopping: Bool = false // Define isStopping here
|
||||||
|
var hasSource = false
|
||||||
|
|
||||||
// MARK: - Initialization
|
// MARK: - Initialization
|
||||||
|
|
||||||
@@ -157,6 +158,7 @@ class VlcPlayerView: ExpoView {
|
|||||||
self.setSubtitleTrack(subtitleTrackIndex)
|
self.setSubtitleTrack(subtitleTrackIndex)
|
||||||
|
|
||||||
self.mediaPlayer?.media = media
|
self.mediaPlayer?.media = media
|
||||||
|
hasSource = true
|
||||||
|
|
||||||
if autoplay {
|
if autoplay {
|
||||||
print("Playing...")
|
print("Playing...")
|
||||||
@@ -280,15 +282,11 @@ class VlcPlayerView: ExpoView {
|
|||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
|
|
||||||
@objc private func applicationWillResignActive() {
|
@objc private func applicationWillResignActive() {
|
||||||
if !isPaused {
|
|
||||||
pause()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func applicationDidBecomeActive() {
|
@objc private func applicationDidBecomeActive() {
|
||||||
if !isPaused {
|
|
||||||
play()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func performStop(completion: (() -> Void)? = nil) {
|
private func performStop(completion: (() -> Void)? = nil) {
|
||||||
|
|||||||
Reference in New Issue
Block a user