React Native:如何以编程方式全屏播放 webview 视频?

时间:2021-04-12 12:01:56

标签: react-native webview android-webview

我在 React Native 应用程序中使用 Webview 来播放 YouTube 视频。我想默认全屏播放视频

代码

   import React, { useState, useEffect,useCallback, useRef  } from 'react';
    import { Text, Button, TouchableOpacity,Alert, View, Image, StyleSheet } from "react-native";
    import { WebView } from 'react-native-webview';
    const MediaPlayer = (props) => {
    
    console.log("props media player is ",props)
        return (
          <WebView
            style={{flex:1}}
            allowsFullscreenVideo={true}
            javaScriptEnabled={true}
            source={{uri: 'https://www.youtube.com/embed/ZZ5LpwO-An4?rel=0&autoplay=0&showinfo=0&controls=1&fullscreen=1'}}
    />
    
        );
    }
    const styles = StyleSheet.create({
       
    })

export default MediaPlayer;

如上所示,我已尝试在视频 url 中传递 url 参数 fullscreen=1 但它没有效果。尝试了 controls=1 和 controls=0 并且它按预期工作,但默认情况下我无法全屏播放此视频。我可以通过单击 webview 视频上的全屏图标来全屏播放视频,但是有没有办法以编程方式全屏播放视频,或者如何让 fullScreen=1 参数起作用?任何帮助表示赞赏

0 个答案:

没有答案