How to Embed YouTube Video in Android WebView
https://www.viralandroid.com/2015/09/how-to-embed-youtube-video-in-android-webview.html
Android WebView is used to display web content in android app. To display web page in android application, WebView uses webkit. In this example, I will show how to embed and play YouTube video in android web view. Embedding YouTube video in android web view is very simple. Follow the following instructions to embed and play YouTube video in android app.
Related:
Implementing Navigation Back Feature to Android WebView Application
How to Load HTML Data/String on Android WebView Application
To embed YouTube video in android web view, first you have to add WebView to your XML activity layout and add little bit code in java activity file.
Let’s start creating a new android project to embed YouTube video in WebView with following information.
Application Name: Embed YouTube Video in WebView
Company Domain: viralandroid.com
Package Name: com.viralandroid.embedyoutubevideoinwebview
Minimum SDK: Android 2.2 (API 8 Froyo)
You can directly drag and drop WebView to your app xml layout. After adding WebView, your XML activity layout looks like this.
res/layout/activity_main.xml
Following is the final code of java activity file. Here, I have added YouTube video embed code in string and some code to control web view.
src/MainActivity.java
Before running your application, you have to add internet permission in your AndroidManifest.xml file. Final code of your manifest file is looks like this.
You have done all things. Now run your application, your app will like this.
Related:
Implementing Navigation Back Feature to Android WebView Application
How to Load HTML Data/String on Android WebView Application
Embed and Play YouTube Video in Android WebView
To embed YouTube video in android web view, first you have to add WebView to your XML activity layout and add little bit code in java activity file.
Create a new Android Project
Let’s start creating a new android project to embed YouTube video in WebView with following information.
Application Name: Embed YouTube Video in WebView
Company Domain: viralandroid.com
Package Name: com.viralandroid.embedyoutubevideoinwebview
Minimum SDK: Android 2.2 (API 8 Froyo)
Add WebView in XML Layout
You can directly drag and drop WebView to your app xml layout. After adding WebView, your XML activity layout looks like this.
res/layout/activity_main.xml
Add YouTube Embed Code in Java Activity
Following is the final code of java activity file. Here, I have added YouTube video embed code in string and some code to control web view.
src/MainActivity.java
Add Internet Permission
Before running your application, you have to add internet permission in your AndroidManifest.xml file. Final code of your manifest file is looks like this.
AndroidManifest.xml
You have done all things. Now run your application, your app will like this.