How to start a bare React Native Typescript + Video project #20
-
Okay I am just trying to set up just a simple Video project to test on and tinker on stuff. I am getting a few different errors and could very well be something I am doing, but I have been googling and I can't quite figure it out.
This one I looked in the "types.ts" and I didn't notice resizeMode in there. I tried to add it and then ran yarn, but I still get the error. How I tried to add it:
I then get several repeating errors :
This is probably something I didn't set up correctly. I did the react-native-video instructions. Here is my App.js with my video object.
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
hey @esegebart I just tried the code you provided. It works for me, except I found one error: That semicolon should be removed. Can you provide more info? For example, how did you start a new project? Does it also have TypeScript? |
Beta Was this translation helpful? Give feedback.
-
@esegebart I just tried with a bare React Native typescript template and it seems to be working? You can follow these steps:
Use the following code snippet: import React, {useRef, useState} from 'react';
import {View, Dimensions, StyleSheet} from 'react-native';
import VideoPlayer from 'react-native-media-console';
import Video, {OnProgressData, OnSeekData} from 'react-native-video';
const HEIGHT = Dimensions.get('window').height;
const WIDTH = Dimensions.get('window').width;
const App = () => {
const videoRef = useRef<Video>(null);
const [paused, setPaused] = useState(false);
const [currentTime, setCurrentTime] = useState(0.0);
const [isVideoReady, setIsVideoReady] = useState(false);
const onLoad = () => setIsVideoReady(true);
const onProgress = (data: OnProgressData) => setCurrentTime(data.currentTime);
const onSeek = (data: OnSeekData) => setCurrentTime(data.seekTime);
const onEnd = () => setPaused(true);
return (
<View style={{flex: 1, height: HEIGHT, width: WIDTH}}>
<VideoPlayer
videoRef={videoRef}
source={{uri: 'https://vjs.zencdn.net/v/oceans.mp4'}}
// navigator={props.navigator}
onLoad={onLoad}
onProgress={onProgress}
onSeek={onSeek}
onEnd={onEnd}
showDuration
showHours
resizeMode={'contain'}
controlTimeoutDelay={5000}
isFullscreen
paused={paused}
style={{
top: 0,
left: 0,
bottom: 0,
right: 0,
position: 'absolute',
width: '100%',
}}
/>
</View>
);
};
const styles = StyleSheet.create({});
export default App; If you run into trouble, let me know. Good luck! |
Beta Was this translation helpful? Give feedback.
-
@esegebart It's also possible that you ran |
Beta Was this translation helpful? Give feedback.
@esegebart I just tried with a bare React Native typescript template and it seems to be working? You can follow these steps:
npx react-native init TSTemplateInit --template react-native-template-typescript
cd TSTemplateInit && yarn add react-native-video react-native-media-console
yarn add --dev @types/react-native-video
cd ios && pod install && cd ..
yarn start
yarn ios
Use the following code snippet: