Play youtube video in an android application

November 20, 2012 | Rishabh Agrawal | General

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_ji2apr6AxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOr_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


THE AUTHORRishabh Agrawal

Rishabh Agrawal is the founder of Creatiosoft, a company focused on creating high-quality software for the iGaming industry, specialising in poker and card games. With years of experience, Rishabh is dedicated to delivering engaging and user-friendly gaming experiences. Through this blog, he shares his passion and insights to help readers understand the latest trends and advancements in iGaming.

Recent Posts

The Future of Mobile Gaming: What to Expect in the Next 5 Years

Over the years, mobile gaming has seen amazing development and innovation utilized by the game development company in India. It…
06 Jun 2023 Rishabh Agrawal

How Do I Get Started With NFT Gaming?

The popularity of the NFT game has created a different fan base. There was a time when games were a…
18 Jul 2022 Rishabh Agrawal

What Are The Top Trends in NFT Marketplace 2022?

The NFTs are the new engaging and revolutionary technology across the globe. Though, these non-fungible tokens appeared for the first…
09 Jun 2022 Rishabh Agrawal