I have implemented react native video in tabs(tabs are implemented using native base) but while moving to other tab(ontabpress) video still plays in background.Any help will be appericated.Thanks
Asked
Active
Viewed 1,757 times
1
-
2Have you tried pausing the video ontabpress? https://github.com/react-native-community/react-native-video#paused – Laurie Williams Jul 31 '18 at 14:49
2 Answers
2
import {useNavigation} from '@react-navigation/native';
const [pause, setPause] = useState(false);
const navigation = useNavigation();
useEffect(() => {
navigation.addListener('focus', (route) => { setPause(false) });
navigation.addListener('blur', (route) => { setPause(true) });
}, []);
<Video
source={{ uri: item.uri }}
rate={1.0}
volume={1.0}
paused={pause}
resizeMode="cover"
shouldPlay={play}
isLooping
style={{
width: '100%',
height: '100%',
}}
/>
Hope this will help you for sure. :)

Kishan Madhesiya
- 347
- 4
- 7
0
Try this
{...}
const [pause, setPause] = useState(false)
useEffect(() => {
const blur = navigation.addListener('blur', () => {
setPause(true)
});
const focus = navigation.addListener('focus', () => {
setPause(false)
});
return blur, focus;
}, [navigation]);
{...}
<Video
source={{ uri: ENTER_HERE_URL }}
paused={pause}
style={styles.bgView} />
{...}

Mahesh Bokhani
- 123
- 1
- 4