Tuesday, April 28, 2015

Android playing Youtube video

Below is the launch scheme to launch the native Android You tube player 

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:VIDEO_ID"));
startActivity(i);

Now, we can also check whether this launch scheme is supported by the below code and decide to show an error message or laugh a web view and pass the link 

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoID));
List list = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() == 0) {
    // default youtube app not present or doesn't conform to the standard we know
    // use our own activity
    i = new Intent(getApplicationContext(), YouTube.class);
    i.putExtra("VIDEO_ID", videoID);
}
startActivity(i);


If want to launch in wbeview, just give the URL for the web view as the youtube link such as https://www.youtube.com/watch?v=6SRQQ1jdBJw 

References:

No comments:

Post a Comment