【问题标题】:How to pause video when moving to other tab in react native如何在本机反应中移动到其他选项卡时暂停视频
【发布时间】:2018-07-31 13:57:45
【问题描述】:

我已经在标签中实现了反应原生视频(标签是使用原生基础实现的),但是在移动到其他标签(ontabpress)时,视频仍然在后台播放。任何帮助都会得到帮助。谢谢

【问题讨论】:

标签: react-native react-native-video


【解决方案1】:
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%',
      }}
    />

希望这对您有帮助。 :)

【讨论】:

    【解决方案2】:

    试试这个

     {...}
    
       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} />
    
     {...}
    

    【讨论】:

      猜你喜欢
      • 2016-06-29
      • 2021-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-03
      • 2014-11-25
      • 2015-03-17
      • 1970-01-01
      相关资源
      最近更新 更多