开发者

YouTube video in Android

开发者 https://www.devze.com 2023-02-14 10:31 出处:网络
I am trying to load a YouTube video in Android. I have added a WebView in xml: <WebView android:id=\"@+id/VideoView\"

I am trying to load a YouTube video in Android.

I have added a WebView in xml:

  <WebView android:id="@+id/VideoView"
           android:layout_height="fill_parent"
           android:layo开发者_如何学Pythonut_width="fill_parent" />

I then load it as follows:

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");

I have added the proper permissions to the manifest. All I receive is a blank white screen and nothing loads.

Can someone please help me with this?


Instead of using webview, just start a new Intent...

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

精彩评论

暂无评论...
验证码 换一张
取 消