Files
EMI-ExpoAPP/components/VideoPlayer.js
2022-03-30 21:37:43 -07:00

52 lines
1.3 KiB
JavaScript

import * as React from 'react';
import { View, StyleSheet, Button } from 'react-native';
import { Video, AVPlaybackStatus } from 'expo-av';
import API from '../API';
import { useSnapshot } from 'valtio';
import GlobalState from '../contexts/GlobalState.js';
const VideoPlayer = ({ videosFiles, videoId, poster }) => {
const gState = useSnapshot(GlobalState);
const viewer = gState.me;
let chosenVideo = [];
videosFiles.forEach((f) => {
if (f.rendition === 'adaptive') chosenVideo.push(f);
});
const video = React.useRef(null);
const [status, setStatus] = React.useState({});
const onLoad = ()=>{
if(!viewer.data[videoId]) return 0;
video.current.setPositionAsync(viewer.data[videoId].time*1000);
};
return (
<Video
ref={video}
style={styles.video}
source={{
uri: chosenVideo[0].link,
}}
usePoster={true}
posterSource={poster ? {
uri: poster
} : ''}
useNativeControls
resizeMode="contain"
isLooping
shouldPlay={false}
onPlaybackStatusUpdate={status => setStatus(() => status)}
onLoad={onLoad}
/>
);
}
export default VideoPlayer;
const styles = StyleSheet.create({
video: {
alignSelf: 'center',
width: 320,
height: 200,
},
});