How to open the youtube app using Intent
you can open it using the package name com.google.android.youtube
start application knowing package name
Intent.getLaunchIntentForPackage("com.google.android.youtube");
How to play YouTube video via Intent?
This code i have used to play youtube video
Matcher matcher = Pattern.compile("http://www.youtube.com/embed/").matcher(mVideoId);
matcher.find()
Intent lVideoIntent = new Intent(
null,
Uri.parse("ytv://" + mVideoId),
MainScreen.mContext,
com.kids.youtube.OpenYouTubePlayerActivity.class);
startActivity(lVideoIntent);
Intent to play playlist in youtube app
After doing some more research, I figured out how to open a playlist within the youtube app
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);
I'm still not quite sure how to automatically start playing the first video though...
Open youtube video at a specific time using android intent
YouTube have a great way of indicating time in their URL for the videos.
- So let's say a
url
of a video is
https://www.youtube.com/watch?v=Z149x12sXsw - You can reference the same URL with it playing automatically 30
seconds in by putting&t=0m30s
at the end. - When you open the video, pass in the new
url
with the new
extension. It should look something like
https://www.youtube.com/watch?v=Z149x12sXsw&t=0m30s
The Intent
will look something like startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=Z149x12sXs" + time)));
where String time = "&t=0m30s";
Edit: Expansion for YouTube App.
public static void watchYoutubeVideo(String id, String time){
Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id + time));
Intent webIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.youtube.com/watch?v=" + id + time));
try {
startActivity(appIntent);
} catch (ActivityNotFoundException ex) {
startActivity(webIntent);
}
}
Using another answer from that question. The same logic can be applied to any intent just add the Time
string to the URI
like shown above regardless of intention.
How to open a Youtube video link directly from android app?
you can set package name of youtube application
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=bzSTpdcs-EI"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.google.android.youtube");
startActivity(intent)
Related Topics
How to Use "Share Image Using" Sharing Intent to Share Images in Android
Change Volley Timeout Duration
Check Android Application Is in Foreground or Not
How to Pass a Variable from Activity to Fragment, and Pass It Back
How to Modify Arrayadapter in Listview: Unsupportedoperationexception
Android: Progressdialog.Show() Crashes with Getapplicationcontext
Android Studio Marks R in Red with Error Message "Cannot Resolve Symbol R", But Build Succeeds
How Are Android Touch Events Delivered
Android: How to Display Video Thumbnails
Eclipse Giving Error, Missing R.Java File After Recent Update
How to Add a Button Dynamically in Android
Self-Signed Ssl Acceptance on Android
How to Change the Background Color of Action Bar'S Option Menu in Android 4.2
How to Disable Gradle 'Offline Mode' in Android Studio
Change Screen Orientation Programmatically Using a Button
How to Determine Android Physical Screen Height in Cm or Inches