1

In my program i am launching Youtube Playlist, but it always showing dialog to choose the way to open, options like:- Browser, Youtube etc.

may i know if i directly want to call using Youtube, without showing any dialog, so what i need to use, see my code below:

Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://www.youtube.com/playlist?list=PL2F07DBCDCC01493A"));
            startActivity(intent);

3 Answers3

1

You can try with following code.

This code will directly start the default Youtube app to play the youtube video.

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

EDIT :

Uri uri = Uri.parse("http://www.youtube.com/playlist?list=" + playlist_id);
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(uri);
    i.setClassName("com.google.android.youtube", "com.google.android.youtube.app.froyo.phone.PlaylistActivity");
    startActivity(i);
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
0

The Video Can be played in two different ways:

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

The id is the identifier after the questionmark in the url. For example: "youtube.com/watch?v=ID"

Another way is:

String url="http://www.youtube.com/watch?v=xxxxxxxxx";
    Intent videoIntent = new Intent(Intent.ACTION_VIEW);
    videoIntent.setData(Uri.parse(url));
    videoIntent.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
    startActivity(videoIntent);
Anchit Mittal
  • 3,412
  • 4
  • 28
  • 48
  • The method setData(Uri) in the type Intent is not applicable for the arguments (String) using this: videoIntent.setData("https://www.youtube.com/playlist?list=PL2F07DBCDCC01493A"); – PatharKeSanam Dec 30 '13 at 05:58
  • not done, able to launch youtube, but not getting Playlist, i guess problem in this line: "com.google.android.youtube.WatchActivity" – PatharKeSanam Dec 30 '13 at 06:16
-1

Let's check it once, i believe this will resolve your issue, just copy and paste my code:

    Intent intent =new Intent(Intent.ACTION_VIEW);
    intent.setPackage("com.google.android.youtube");
    intent.setData(Uri.parse("https://www.youtube.com/playlist?list=PL2F07DBCDCC01493A"));
    startActivity(intent);

and let me know if you have any query ? ok !

Android
  • 1,529
  • 1
  • 12
  • 27