How can we play YouTube embeded code in an Android application using webview?
1. Locate the video you wish to use and click on the Share link located beneath the video. 2. Next, click on the Embed icon The embed code will then be displayed.
Google combined WebView with Google Chrome for versions 7.0, 8.0 and 9.0. However, with Android 10.0, it went back to having it as a separate component. Users can update WebView in Android 10 through Google Play Store.
Check out the following SO post: How to embed a YouTube clip in a WebView on Android
Try the following code which may help you. I just framed it for your reference
myWebView = (WebView) findViewById( R.id.webview_compontent );
String playVideo= "<html><body>Youtube video .. <br> <iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/bIPcobKMB94\" frameborder=\"0\"></body></html>"
myWebView.loadData(playVideo, "text/html", "utf-8");
Refer the following link for how to use Webview: http://developer.android.com/reference/android/webkit/WebView.html
Add WebView in XML File
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
And in Java File
String frameVideo = "<html><body>Youtube video .. <br> <iframe width="320" height="315" src="https://www.youtube.com/embed/lY2H2ZP56K4" frameborder="0" allowfullscreen></iframe></body></html>";
WebView displayVideo = (WebView)findViewById(R.id.webView);
displayVideo.loadData(frameVideo, "text/html", "utf-8");
For Tutorial:
How to embed youtube video in android
Android WebVew tutorial with example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With