1

Possible Duplicate:
Android YouTube app Play Video Intent

I wanted to know how to open Youtube App on Android directly using intent.

What i have:

        @Override
        public void onClick(View v) {
        String video_path = "http://www.youtube.com/user/videoslusofona";
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(video_path));
        startActivity(intent);
        }

What i don't want is for Android to ask me what App i want to open, i want to open Youtube App directly on click.

Thanks for your time

Community
  • 1
  • 1
jsfrocha
  • 1,812
  • 2
  • 21
  • 32
  • Sadly, the link you provided works only for single videos to watch on youtube (as I explained in the answer below), not to display a user's channel on youtube. Or maybe i'm missing something ? – jsfrocha Dec 11 '12 at 20:35

1 Answers1

1

you can try:

String videoId = "VideoIDGoesHere";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId)); 
intent.putExtra("VIDEO_ID", videoId); 
startActivity(intent);

You might want to look at using

Intent lVideoIntent = new Intent(null, Uri.parse("ytpl://"+YOUTUBE_PLAYLIST_ID), this, OpenYouTubePlayerActivity.class);
startActivity(lVideoIntent);

from the wiki, you'll need to have the playlist id but it seems like this should work.

John Boker
  • 82,559
  • 17
  • 97
  • 130
  • It opens the Youtube APP but as `"http://www.youtube.com/user/videoslusofona"` isn't a particular video to watch, but instead a list of videos from a user, the Youtube APP says : `Invalid Request`. Actually i had already seen that code, just haven't tried it because i thought (and now confirmed) it only worked for single videos. – jsfrocha Dec 11 '12 at 20:32
  • I prefer, whenever I can, to save the video id in the file strings.xml This can help in putting multiple video ids in different spoken languages. let's say you make two explanations for the same subject one in English and another in Arabic and at the same time you don't use subtitles because you already know both languages. So, this way you'll have in your project 2 folders 'values' for English strings as default, and 'values-ar' for Arabic strings. You'll get automatic switch between En/Ar video. In code: String videoId = getString(R.string.help_youtube_video_id); – superlinux Jun 03 '14 at 06:54