2011-03-02 90 views
1

我正尝试在Android中加载YouTube视频。Android中的YouTube视频

我在XML加入web视图:

<WebView android:id="@+id/VideoView" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" /> 

我然后如下加载:

WebView webview = new WebView(this); 
setContentView(R.layout.webview); 

String htmlString = "<html> <body> <embed src=\"http://www.youtube.com/watch?v=XS998HaGk9M\"; type=application/x-shockwave-flash width="+640+" height="+385+"> </embed> </body> </html>"; 
webview.loadData(htmlString, "text/html", "utf-8"); 

我已经加入适当的权限到清单。我收到的只是一个空白的白色屏幕,没有任何负载。

有人可以帮助我吗?

回答

5

而不是使用webview的,刚开始一个新的Intent ...

startActivity(new Intent(Intent.ACTION_VIEW, 
     Uri.parse("http://www.youtube.com/watch?v=XS998HaGk9M"))); 
+1

+1因为这也将允许其不支持闪光灯UE在YouTube客户端较旧的手机。 – Basic 2011-03-02 02:16:46

+0

我试图使用,但我得到一个网页不可用。此外,我想尝试控制视图的多少部分将显示YouTube视频,这就是为什么我使用了webview。 – Tommy 2011-03-02 02:20:31

+0

如果网页不可用,那么这是你的问题;-) – schwiz 2011-03-02 02:32:25