Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we play YouTube embeded code in an Android application using webview?

How can we play YouTube embeded code in an Android application using webview?

like image 472
Droid Avatar asked Apr 28 '11 11:04

Droid


People also ask

How do I get the YouTube embed code on my phone?

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.

Which browser is used in Android WebView?

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.


2 Answers

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

like image 82
Vinayak Bevinakatti Avatar answered Sep 21 '22 07:09

Vinayak Bevinakatti


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:

  1. How to embed youtube video in android

  2. Android WebVew tutorial with example

like image 39
Sajan Rana Avatar answered Sep 21 '22 07:09

Sajan Rana