2010-12-22 174 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"); 
相關問題