Reputation: 206
I have tried the following code to run a YouTube video in video view.But its says this video cant be played...
video = (VideoView) findViewById(R.id.VideoView);
String path = "rtsp://v5.cache4.c.youtube.com/CjYLENy73wIaLQmiWeecHAQBrBMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYMWyte6X6MbcUAw=/0/0/0/video.3gp";
Uri uri = Uri.parse(path);
video.setVideoURI(uri);
video.start();
Any solution please...
Upvotes: 2
Views: 1683
Reputation: 25757
In response to the question comments this is how to use an intent that can result in YouTube app playing a YouTube video.
Intent viewIntent = new Intent("android.intent.action.VIEW", "url_to_video");
startActivity(viewIntent);
Obviously the YouTube app has to be installed and if there are multiple apps that can handle playback the user may be prompted to choose one, if they haven't selected a default app already.
If you want to see this in action you can see it in one of our free apps under the video section. We pop a Dialog to ask if the user wants to view the video in case they are on a limited bandwidth connection (e.g. 3G).
https://play.google.com/store/apps/details?id=wisemandesigns.android.robgreen&hl=en
Upvotes: 2
Reputation: 13785
Once you get the You tube url..., Substring the Video_ID from the Url.See the example below i have given.
You can use http://gdata.youtube.com/feeds/mobile/videos/VIDEO_ID api to get the rtsp link from the actual you tube url.Data is in XML format
once you get the rtsp link you can play video in VideoView here is the example
For example: If this link is the video http://www.youtube.com/watch?v=sMM0R19IisI
Then sMM0R19IisI
is the Video_ID.So you can pass this video id to above api to get the rtsp link
To get Data in JSON format
use this http://gdata.youtube.com/feeds/mobile/videos/"+videoid+"?alt=json
Refer these two links:
Once you get the rtsp link you can play it in VideoView
Upvotes: 1