Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed youtube video in Webview of React Native

I am trying to play Youtube videos in react native android/ios app. I have defined a webview:

<WebView
    style={styles.frame}
    url={this.props.url}
    renderLoading={this.renderLoading}
    renderError={this.renderError}
    automaticallyAdjustContentInsets={false}
/>

And passing the url of the video I want to play:

this.navigate('Play', 'https://www.youtube.com/watch?v=RJa4kG1N3d0')

But this displays the whole youtube page in the webview including the comments section.

enter image description here

I want to display only the video section and not the comment section. Is there anything missing in the url?

like image 569
triandicAnt Avatar asked Jul 01 '16 19:07

triandicAnt


People also ask

How do I play a youtube video in react-native WebView?

/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local */ import React from 'react'; import {View} from 'react-native'; import YoutubePlayer from 'react-native-youtube-iframe'; const App = () => { return ( <View> <YoutubePlayer height={300} play={true} videoId={' ...

How do I embed a Youtube video in react-native?

To achieve playing Youtube videos in React Native, we will be making use of the npm dependency named react-native-youtube-iframe. We will work through using this library by fully integrating it into an app.

Can we use WebView in react-native?

WebViews offer developers opportunities to render any web components in a React Native application. A web component can be anything from a whole webpage/application or just a simple HTML file. The package react-native-webview makes it super simple to embed WebViews into your React Native apps!


1 Answers

The easiest way to embed YouTube in the React Native iOS device is to use the <WebView>. All you need to do is to replace watch?v= with embed. This will not work with Android.

Example:

<WebView
        style={{flex:1}}
        javaScriptEnabled={true}
        source={{uri: 'https://www.youtube.com/embed/ZZ5LpwO-An4?rel=0&autoplay=0&showinfo=0&controls=0'}}
/>
like image 147
vincent mathew Avatar answered Sep 24 '22 16:09

vincent mathew