Play a video on Youtube using an Intent

Posted by Marco Dinacci on 0 comments

Warning! For this demo to work the user needs the Youtube application installed on his device.

public void onCreate(Bundle savedInstanceState) {
    String video_path = "";
    Uri uri = Uri.parse(video_path);
    // With this line the Youtube application, if installed, will launch immediately.
    // Without it you will be prompted with a list of the application to choose.
    uri = Uri.parse(""  + uri.getQueryParameter("v"));
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);

The example uses a standard Youtube URL. The


is used to extract the video ID from the URI itself, in this example the ID is opZ69P-0Jbc