Tommy
Tommy

Reputation: 759

YouTube video in Android

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:layout_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?

Upvotes: 1

Views: 1083

Answers (1)

Ryan Berger
Ryan Berger

Reputation: 9732

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

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

Upvotes: 5

Related Questions