我正在尝试将 youtube 视频嵌入到我的 react-native 应用程序中,它工作正常,但我无法获得这些视频的全屏按钮/功能。这是我的代码:
<WebView
source={{uri: "https://www.youtube.com/embed/VaC9CivyV7I?version=3&enablejsapi=1&rel=0&autoplay=1&showinfo=0&controls=1&modestbranding=0"}}
style={{height:240, width:width, justifyContent:'center', alignItems:'center', backgroundColor:'black'}}
/>
我什至尝试使用
iframe
作为 allowfullscren="true"
的 html ,但我没有得到任何成功。编辑
经过更多的搜索,我发现了这个文档 for Full screen support ,并知道我需要实现
onShowCustomView
和 onHideCustomView
内webView.setWebChromeClient
,我在我的应用程序的 node_modules 文件夹中挖掘了一点,发现了 ReactWebViewManager.java
在位置 *"../node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java"。看来可能需要添加一些自定义代码webView.setWebChromeClient,但由于我对 native 编程不太擅长,因此无法进一步进行。
最佳答案
WebView
组件接受 allowsFullscreenVideo
支柱。当此 Prop 为真时,全屏图标将变为事件状态。
见 https://github.com/react-native-community/react-native-webview/blob/master/docs/Reference.md#allowsfullscreenvideo .
关于webview - react-native webview 嵌入 youtube 视频在 Android 中没有全屏选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40845156/