fix: loader position

This commit is contained in:
Fredrik Burmester
2024-11-27 08:59:31 +01:00
parent 88a3bdd891
commit 2db4effef5
3 changed files with 81 additions and 65 deletions

View File

@@ -339,7 +339,8 @@ export default function page() {
useFocusEffect( useFocusEffect(
React.useCallback(() => { React.useCallback(() => {
return () => { return async () => {
await reportPlaybackStopped();
videoRef.current?.stop(); videoRef.current?.stop();
}; };
}, []) }, [])
@@ -442,6 +443,21 @@ export default function page() {
writeToLog("ERROR", "Video Error", e.nativeEvent); writeToLog("ERROR", "Video Error", e.nativeEvent);
}} }}
/> />
<View
style={{
position: "absolute",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
opacity: isBuffering ? 1 : 0,
width: "100%",
height: "100%",
}}
pointerEvents="none"
>
<Loader />
</View>
</View> </View>
{videoRef.current && ( {videoRef.current && (
<Controls <Controls

View File

@@ -407,54 +407,70 @@ const Player = () => {
}} }}
> >
{videoSource ? ( {videoSource ? (
<Video <>
ref={videoRef} <Video
source={videoSource} ref={videoRef}
style={{ source={videoSource}
height: "100%", style={{
width: "100%", height: "100%",
}} width: "100%",
resizeMode={ignoreSafeAreas ? "cover" : "contain"} }}
onProgress={onProgress} resizeMode={ignoreSafeAreas ? "cover" : "contain"}
onError={(e) => { onProgress={onProgress}
console.error("Error playing video", e); onError={(e) => {
}} console.error("Error playing video", e);
onLoad={() => { }}
if (firstTime.current === true) { onLoad={() => {
play(); if (firstTime.current === true) {
firstTime.current = false; play();
} firstTime.current = false;
}} }
progressUpdateInterval={500} }}
playWhenInactive={true} progressUpdateInterval={500}
allowsExternalPlayback={true} playWhenInactive={true}
playInBackground={true} allowsExternalPlayback={true}
pictureInPicture={true} playInBackground={true}
showNotificationControls={true} pictureInPicture={true}
ignoreSilentSwitch="ignore" showNotificationControls={true}
fullscreen={false} ignoreSilentSwitch="ignore"
onPlaybackStateChanged={(state) => { fullscreen={false}
if (isSeeking.value === false) setIsPlaying(state.isPlaying); onPlaybackStateChanged={(state) => {
}} if (isSeeking.value === false) setIsPlaying(state.isPlaying);
onTextTracks={(data) => { }}
setEmbededTextTracks(data.textTracks as any); onTextTracks={(data) => {
}} setEmbededTextTracks(data.textTracks as any);
onBuffer={(e) => { }}
setIsBuffering(e.isBuffering); onBuffer={(e) => {
}} setIsBuffering(e.isBuffering);
onAudioTracks={(e) => { }}
console.log("onAudioTracks: ", e.audioTracks); onAudioTracks={(e) => {
setAudioTracks( console.log("onAudioTracks: ", e.audioTracks);
e.audioTracks.map((t) => ({ setAudioTracks(
index: t.index, e.audioTracks.map((t) => ({
name: t.title ?? "", index: t.index,
language: t.language, name: t.title ?? "",
})) language: t.language,
); }))
}} );
selectedTextTrack={selectedTextTrack} }}
selectedAudioTrack={selectedAudioTrack} selectedTextTrack={selectedTextTrack}
/> selectedAudioTrack={selectedAudioTrack}
/>
<View
style={{
position: "absolute",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
opacity: isBuffering ? 1 : 0,
width: "100%",
height: "100%",
}}
pointerEvents="none"
>
<Loader />
</View>
</>
) : ( ) : (
<Text>No video source...</Text> <Text>No video source...</Text>
)} )}

View File

@@ -392,22 +392,6 @@ export const Controls: React.FC<Props> = ({
}} }}
></Pressable> ></Pressable>
<View
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
}}
pointerEvents="none"
className={`flex flex-col items-center justify-center
${isBuffering ? "opacity-100" : "opacity-0"}
`}
>
<Loader />
</View>
<View <View
style={[ style={[
{ {