-1

I want to play YouTube videos on Android without using YouTube app. It should play with Android player. We have tried using YouTube app, but we need to play YouTube videos directly with Android player, not using YouTube application.

Is it possible? If it is, how to do it?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
AnilPatel
  • 2,356
  • 1
  • 24
  • 40
  • Duplicate of http://stackoverflow.com/questions/19534647/how-to-play-youtube-video-in-android-native-player – 323go Feb 21 '14 at 14:24

2 Answers2

-1

try this.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    VideoView videoView = (VideoView) findViewById(R.id.VideoView);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    // Set video link (mp4 format )
    Uri video = Uri.parse("your url in rtsp format");
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);
    videoView.start();
}
azhar
  • 1,709
  • 1
  • 19
  • 41
-1

Its simple just create video view then add a new media controller to it, set the video URL in the video view and start the video it will work.

Add the below Code into your MainActivity.java file. @Override

 protected void onCreate(Bundle savedInstanceState)

      // TODO Auto-generated method stub
     super.onCreate(savedInstanceState);
     try {
     setContentView(R.layout.videodisplay);
     String link="http://www.youtube.com/watch?v=JSnB06um5r4";
     VideoView videoView = (VideoView) findViewById(R.id.VideoView);
     MediaController mediaController = new MediaController(this);
     mediaController.setAnchorView(videoView);
     Uri video = Uri.parse(link);
     videoView.setMediaController(mediaController);
     videoView.setVideoURI(video);
     videoView.start();
 } catch (Exception e) {
     // TODO: handle exception
     Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
 }

}

You better try it on offline file to make sure that the video viewer is working fine (the video is compatible with device) then play it online

MJBLACKEND
  • 121
  • 1
  • 3