2010-12-22 170 views
1

我想在android中的webview中播放YouTube视频,该视频不应在新窗口中打开。它应该只能在android的webview中播放。如何在android中的webview中播放Youtube视频?

+0

有没有像如C#WinForm的web浏览器,你可以在Android上使用任何控制?也许你可以使用一些控制来实现它。 我只知道一点关于android,希望这可以帮助你。 – 2011-02-11 10:06:32

+0

也许这个解决方案将帮助:http://stackoverflow.com/questions/7257389/youtube-video-not-showing-in-webview/7790908#7790908 – Ronnie 2011-10-17 08:07:56

回答

3

你可以试试这个,它适合我。

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"); 
相关问题