Play youtube video in an android application

We can play youtube videos inside our android  application using VideoView.

VideoView displays a video file. The VideoView class can load images from various sources , takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling and tinting.

Using Video View:

1.Code in the  layout xml:


<VideoView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/YoutubeVideoView" />

2.Code in java class:


VideoView v = (VideoView) findViewById(R.id.YoutubeVideoView);

v.setVideoURI(Uri                             .parse("rtsp://v4.cache3.c.youtube.com/CjYLENy73wIaLQlW_ji2apr6AxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOr_86Xm06e5UAw=/0/0/0/video.3gp"));

v.setMediaController(new MediaController(this)); //sets MediaController in the video view

// MediaController containing controls for a MediaPlayer

v.requestFocus();//give focus to a specific view

v.start();//starts the video

We set the VideoUri by specifying the 3gp link of Youtube video for mobile platforms. To add media controls such as Play, Pause, Rewind, Fast Forward and a progress slider ,we add MediaController to the VideoView.

How to get 3gp link of a Youtube video

  • Right click the video to copy Video URL.
  • Open “m.youtube.com” to get the mobile version videos.
  • Right click on the video to Copy Link Address.
  • The 3gp link of the video looks like this :

The 3gp link of the video looks like this :

rtsp://v4.cache3.c.youtube.com/CjYLENy73wIaLQlW_ji2apr6AxMYDSANFEIJbXYtZ29v

Z2xlSARSBXdhdGNoYOr_86Xm06e5UAw=/0/0/0/video.3gp

Playing youtube videos in android application was that simple !

Download the complete Demo project here for your reference . videoTEST

Advertisements

5 thoughts on “Play youtube video in an android application

  1. Its like you read my mind! You seem to know so much about this,
    like you wrote the book in it or something. I think that
    you can do with a few pics to drive the message home a little
    bit, but instead of that, this is great blog. An excellent read.
    I’ll certainly be back.

  2. Very good blog! Do you have any tips and hints for aspiring writers?
    I’m hoping to start my own website soon but I’m a little lost on everything.
    Would you propose starting with a free platform
    like WordPress or go for a paid option? There are so many options out there that I’m totally confused .. Any recommendations? Thanks a lot!

    • Thanks schilderen|Oppas ! what kind of website you want to start ? Well you can start with a free platform and when your blog catches pace then you can easily move your blog to your domain. I’m a newbie in technical writing too…do your research well on the topic first and then write in a manner that is very easy to understand .Explain the code and you may use some screen shots for better understanding,,Thats it

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s