Android – Youtube video play with android player

android

How will we play youtube video with android media player???

Anybody has idea then please explain me.

I have to play the URL:"http://www.youtube.com/embed/bIPcobKMB94?autoplay=1" with android default media player.

When i played this url with android media player, i got MediaPlayer error (1, -2147483648).

I play that url in my android device media player but now i am not able play in tablet. Anybody help me. Why i am not able to play that video in tablet?

rtsp://v6.cache3.c.youtube.com/CiILENy73wIaGQnokCRYfXXPsBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp

Thanks

Best Answer

Well, the Android part is quite easy. You just need a raw URI of the YouTube video and trigger an intent with it:

    Uri uri = Uri.parse("http://<link-to-RAW-youtube-video>"); // i.e. mp4 version
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, "video/*"); // important! otherwise you just download the video
    startActivity(intent); // called directly from an other activity as you see

If the user has multiple video players installed the user also gets a choice which one he wants to use for the playback.

The tricky part here is not Android related it is how to get the raw URI of a YouTube video. Usually they are extracted from the source code of the original YouTube Video page but that's an other topic. I tried the code above with a self extracted URI to a mp4 version of the video and it worked just fine on my Android 4.0 phone.

EDIT:

You really have to use a raw URI to the YouTube Video, for your Video it would be:

http://o-o.preferred.ber01s04.v22.lscache2.c.youtube.com/videoplayback?sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cexpire&fexp=904550%2C919700%2C911614&itag=18&ip=77.0.0.0&signature=C721CE7543081FC0C805C86F5D3C4D9B34D77764.D4288106CF7A3153FF1574F2334161CBD1176535&sver=3&ratebypass=yes&source=youtube&expire=1332001847&key=yt1&ipbits=8&cp=U0hSR1BLT19JUUNOMl9IRVNJOmllRjJJYy1SSG92&id=6c83dca1b28c07de&title=AT%26T%20Samsung%20Captivate%20TV%20Commercial%20-%20Galaxy%20S%20Phone-360p

It's very long but it will work :)