【问题标题】:Youtube iframe videos do not work in react-native webviewYoutube iframe 视频在 react-native webview 中不起作用
【发布时间】:2019-04-26 06:36:21
【问题描述】:

我在使用 react-native-webview 播放包裹在 iframe 中的 youtube 或 instagram 视频时遇到问题。问题仅在Android中。 IOS 运行良好。

所以,当我将 iframe 放入 webview 时,它看起来没问题。直到我点击播放按钮。视频开始加载,所有本机按钮都可用,声音正常,但电影是黑色的。声音和停止/播放按钮有效。

依赖关系:

react-native-cli: 2.0.1
react-native: 0.57.5
"react-native-webview": "^2.12.1"

我准备了简单的演示,其中视频不起作用:

  render() {
    return (
      <WebView
        originWhitelist={['*']}
        useWebKit={false}
        source={{
          html: `
          XX
          <div>
            <iframe width="320" height="240" src="https://www.youtube.com/embed/li8yILhFFZM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> 
          </div> `

        }}
      />

    );
  }
}

及问题截图:

感谢您的帮助!

【问题讨论】:

  • 在 Android Manifest 文件中只包含 hardwareAccelerated=true。那么黑屏问题就解决了。

标签: android react-native youtube-api android-webview instagram-api


【解决方案1】:

你可以简单地使用 URI 和 react-native 的默认 webview,与 android 配合得很好。

   <View style={styles.cardRounded}>
    <WebView
      mediaPlaybackRequiresUserAction={true}
      style={{ height:240, width:320,alignSelf:"center",alignContent:"center"}}
      source={{uri: 'https://www.youtube.com/embed/li8yILhFFZM?rel=0' }}
    />
   </View>

let styles = StyleSheet.create({
    cardRounded: {
        paddingEnd:0,  paddingTop: 0 , paddingBottom: 0, paddingStart: 0, padding:0,
        borderRadius: 12, alignItems:"center", backgroundColor:#000000,flex:0, height:240,
    },

});

【讨论】:

    猜你喜欢
    • 2014-12-02
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 2020-02-11
    • 2020-06-13
    • 2019-12-21
    相关资源
    最近更新 更多