I have created a app where you can download YouTube videos for android. Now, I want it so that if you play a video in the YouTube native app you can download it too. To do t
The Youtube (and Market application) are only supposed to be used with special ROMs, which Google released for the G1 and the G2. So you can't run them in an OpenSource-ROM, like the one used in the Emulator, unfortunately. Well, maybe you can, but not in an officially supported way.
Found it:
03-18 12:40:02.842: INFO/ActivityManager(68): Starting activity: Intent { action=android.intent.action.VIEW data=(URL TO A FLV FILE OF THE VIDEO) type=video/* comp={com.google.android.youtube/com.google.android.youtube.YouTubePlayer} (has extras) }
Try this:
public class abc extends Activity implements OnPreparedListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
}
}
}
Replying to old question, just to inform you guys that package have changed, heres the update
Intent videoClient = new Intent(Intent.ACTION_VIEW);
videoClient.setData("VALID YOUTUBE LINK WITH HTTP");
videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
startActivity(videoClient);
This works very well, but when you call normal Intent with ACTION_VIEW with valid youtube URL user gets the Activity selector anyways.
Try this,
WebView webview = new WebView(this);
String htmlString =
"<html> <body> <embed src=\"youtube link\"; type=application/x-shockwave-flash width="+widthOfDevice+" height="+heightOfDevice+"> </embed> </body> </html>";
webview.loadData(htmlString ,"text/html", "UTF-8");
This function work fine for me...just pass url string in function:
void watch_video(String url)
{
Intent yt_play = new Intent(Intent.ACTION_VIEW, Uri.parse(url))
Intent chooser = Intent.createChooser(yt_play , "Open With");
if (yt_play .resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
}