1

I want to play a YouTube video in webview in android, which should not open in a new window. It should only play in webview on android.

Waynn Lue
  • 11,344
  • 8
  • 51
  • 76
Urvashi Hirani
  • 343
  • 1
  • 5
  • 5
  • Is there any control like webbrowser like C# winform can you use in android? maybe you can use some control to make it. I just know a little about android, hope this can help you. – Tim Li Feb 11 '11 at 10:06
  • Maybe this solution will help: http://stackoverflow.com/questions/7257389/youtube-video-not-showing-in-webview/7790908#7790908 – Ronnie Oct 17 '11 at 08:07

2 Answers2

3

You can try this one, it works for me.

WebView video = (WebView) findViewById(R.id.video);
String widthAndHeight = "width='220' height='200'";
String videoURL = "http://www.youtube.com/v/DZi6DEJsOJ0?fs=1&hl=nl_NL";

String temp = "<object "+widthAndHeight+">" +
"<param name='allowFullScreen' value='false'>" +
"</param><param name='allowscriptaccess' value='always'>" +
"</param><embed src='"+ videoURL +"'" +
" type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true'" + widthAndHeight +
"></embed></object>";

video.getSettings().setJavaScriptEnabled(true);
    video.getSettings().setPluginsEnabled(true);
    video.loadData(temp,"text/html", "utf-8");
Justin
  • 84,773
  • 49
  • 224
  • 367
aviciena
  • 71
  • 1
  • 1
  • 5
0

Try Android Youtube Player API read more here : https://developers.google.com/youtube/android/player/

subair_a
  • 1,028
  • 2
  • 14
  • 19