Play youtube video in react-native-video

vijay kahar picture vijay kahar · Aug 8, 2019 · Viewed 22.7k times · Source

How can i play youtube video on react-native-video,

i don't want to play video in react-native-youtube or in webview,

Answer

IvanAllue picture IvanAllue · Sep 3, 2019

Another option that I have checked and used is the WebView. To use it make sure you put the component in a View with a flex. Ex:

<View style={{flex: 1}}>
    <WebView
        style={ {  marginTop: (Platform.OS == 'ios') ? 20 : 0,} }
        javaScriptEnabled={true}
        domStorageEnabled={true}
        source={{uri: 'https://www.youtube.com/embed/'+this.state.pictureData.idVideo }}
    />
</View>

in my case, what I did was to obtain the identifying part of the YouTube video that would be for example: https://www.youtube.com/watch?v=KQ6zr6kCPj8

this.state.pictureData.idVideo would contain only: KQ6zr6kCPj8

To use it install:

  1. $ npm install --save react-native-webview
  2. link react-native-webview

and if you want more information: https://github.com/react-native-community/react-native-webview