Is there any way to use the built in iOS/Android video controls for video playback in React Native?
For example, here is what it would look like on iOS
CodePudding user response:
I used expo-av
library to do this. You can also use this library in bare project as well. (https://github.com/expo/expo/tree/master/packages/expo-av)
All you need to do to get the native video controls is pass in useNativeControls
. Heres there code and example (https://snack.expo.dev/@heytony01/video)
import * as React from 'react';
import { View, StyleSheet, Button } from 'react-native';
import { Video, AVPlaybackStatus } from 'expo-av';
export default function App() {
const video = React.useRef(null);
const [status, setStatus] = React.useState({});
return (
<View style={styles.container}>
<Video
ref={video}
style={styles.video}
source={{
uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4',
}}
useNativeControls
resizeMode="contain"
isLooping
onPlaybackStatusUpdate={status => setStatus(() => status)}
/>
<View style={styles.buttons}>
<Button
title={status.isPlaying ? 'Pause' : 'Play'}
onPress={() =>
status.isPlaying ? video.current.pauseAsync() : video.current.playAsync()
}
/>
</View>
</View>
);
}