Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: load background video #86

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/temp-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions components/VideoDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ResizeMode, Video } from "expo-av";
import { useState } from "react";
import { ImageBackground } from "react-native";

const RenderPoster = ({ videoLoading, requiredBgImage }) => {
if (!videoLoading) return <></>;
return <ImageBackground source={requiredBgImage} resizeMode={ResizeMode.COVER} imageStyle={{ opacity: 0.9 }} />;
};

const VideoDisplay = ({ requiredBgImage, videoUri }) => {
const [videoLoading, setVideoLoading] = useState(true);

return (
<Video
style={{
flex: 1,
position: "relative",
}}
source={videoUri}
shouldPlay={true}
isLooping={true}
isMuted={true}
resizeMode={ResizeMode.COVER}
usePoster={true}
onPlaybackStatusUpdate={(status) => setVideoLoading(() => status.isLoaded)}
>
<RenderPoster videoLoading={videoLoading} requiredBgImage={requiredBgImage} />
</Video>
);
};
export default VideoDisplay;
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@types/react-native": "^0.70.6",
"expo": "~49.0.0",
"expo-av": "~13.4.1",
"expo-file-system": "~15.4.4",
"expo-file-system": "~15.4.5",
"expo-linking": "^5.0.0",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
Expand Down
16 changes: 4 additions & 12 deletions screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { Video } from "expo-av";
import { Alert, View, Text, TouchableOpacity } from "react-native";

import VideoDisplay from "../components/VideoDisplay";
import Colors from "../styles/colors";
import * as Spacing from "../styles/spacing";
import * as Typography from "../styles/typography";

export default function HomeScreen({ navigation }) {
return (
<>
<Video
style={{
flex: 1,
position: "relative",
}}
source={{ uri: "https://imgur.com/Q8km3ih.mp4" }}
shouldPlay={true}
isLooping={true}
isMuted={true}
resizeMode="cover"
usePoster={true}
<VideoDisplay
requiredBgImage={require("../assets/temp-bg.png")}
videoUri={{ uri: "https://imgur.com/Q8km3ih.mp4" }}
/>
<View
style={{
Expand Down