Skip to content Skip to sidebar Skip to footer

Play Youtube Video From Url In Android

I want to play youtube video in my application. I am getting video URL from SAX Parsing. My question is how to play video from URL in VideoView, not in Webview or Browser. I tried

Solution 1:

Try this way it worked for me ,for playing video from a website

 Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.youtube.com/
                           watchv=JxYSlkh1Src&feature=player_embedded"));
                 startActivity(browserIntent);

Solution 2:

you can try below code for direct play in Youtube application.

IntentvideoClient=newIntent(Intent.ACTION_VIEW);
            videoClient.setData(Uri.parse("https://www.youtube.com/watch?v=EwSdmxyayx0&feature=youtube_gdata"));//you can try here your own video url
            videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.PlayerActivity");
            try{
                startActivity(videoClient);
            }catch(ActivityNotFoundException excp){
                try{
                    videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
                     startActivity(videoClient);
                }catch(ActivityNotFoundException exc){
                    exc.printStackTrace();
                }
            }

Solution 3:

StringvideoUrl="http://www.youtube.com/watch?v=cxLG2wtE7TM"//split video url and get value of v ie cxLG2wtE7TMStringvideoId="cxLG2wtE7TM";
Stringaction= Intent.ACTION_VIEW;
Uriuri= Uri.parse("vnd.youtube:" + videoId);
IntentvideoIntent=newIntent(action, uri);
startActivity(videoIntent);

Solution 4:

Intenti=newIntent(Intent.ACTION_VIEW);
 i.setData(Uri.parse("video url"));
 VideoActivity.this.startActivity(i);

Solution 5:

It is displaying one popup screen with 'Internet' and 'YouTube'

because the ACTION_VIEW intent is written both in default browser and Youtube application. that's why whenever it catches the URL the Browser opens and whenever the Youtube URL is opened Both the browser and Youtube app.

I want to play the video directly in youtube

Take the embed link of Youtube video and set intent it will play the video.

ex:-http://www.youtube.com/embed/srMFb6zpx2Y

Post a Comment for "Play Youtube Video From Url In Android"