Tropical Software Observations

17 January 2012

Posted by Teo Choong Ping

at 9:20 AM

3 comments

The Many Ways to Play Youtube Video for Android

Embedding YouTube videos in a mobile application -- iOS or Android -- is not always straightforward.

We have the GData API for Youtube which is good for getting data on Video or Playlist but not to embed video the way you want. YouTube really wants you to just open the native YouTube app and play it there.

The simplest way is by starting with the intent to load the YouTube video in the native app. It's as easy as the example below -- notice the "vnd.youtube" protocol type.

    Intent intent = new Intent(Intent.ACTION_VIEW, 
                               Uri.parse("vnd.youtube:" 
                             + "SomeYTIdHere" ));
    startActivity(intent);


Now, if for whatever reason the Android device doesn't come with the native YouTube app, you can just open the YouTube mobile page, like this:


    startActivity(newIntent(
              Intent.ACTION_VIEW
              Uri.parse("http://www.youtube.com/v/SomeYTIdHere")));


But if opening the mobile page is not good enough, then another tricky way is to embed the YouTube video "..." stuff in a webview. That usually will work by playing the video with Flash and is tested to work on Android tablets.

If you have a Kindle Fire and you do not want to play the video in the YouTube mobile page, then you can use OpenYouTubeActivity from the android-youtube-player project.

I hope these approaches help you in figuring out the best way to play YouTube content in your Android apps.

3 comments:

Rachita Nanda said...

Thanks for this useful post.
Wow what an awesome website ,so useful !There is another way to play videos using video view .Here a demo project for refrence http://blog.creatiosoft.com/wp-content/uploads/2012/11/videoTEST.rar

shashi said...

i tried this url http://www.youtube.com/watch?v=Eet-QdVcrpw

but invalid request, touch to retry displays on the screen.

jowdjbrown said...

This is exactly the information I'm looking for, I couldn't have asked for a simpler read with great tips like this... Thanks!
Android App Development