Play YouTube video in Android Webview?

Hello friends, today we are going to learn how to play YouTube video in our Android application. It is a very common requirement for every android developer to play video from YouTube so no need to purchase any server.

So as per my knowledge, we can play video from YouTube following two methods.

  1. Embed YouTube video in Android WebView
  2. Use YouTube Android Player API

Embed YouTube video in Android WebView

You might know WebView is used in android coding to display web pages mainly. Similarly, we can also embed YouTube videos in WebView very simply.

1. Put WebView in Activity’s layout or xml file

2. Add Internet permission in AndroidManifest.xml file

3. Copy embed code from YouTube video

To embed the video in webview you have to copy HTML code from a youtube video by right-clicking on a youtube video from the browser and select Copy embed code fourth option.

4. Write following code inside java file of your activity

Related Posts

Leave a Reply