Affiliate links on Android Authority may earn us a commission.Learn more.

Display YouTube, Vimeo, and Dailymotion videos in your Android apps

July 25, 2025

If your latestAndroid appis going to find an audience, then you need to deliver an engaging user experience.

In this article, I’ll show you how to deliver a richer, multimedia experience, by incorporating video content into your Android apps.

Article image

We’ll be exploring the two major ways that you may add videos to your applications:

When you think about online videos, YouTube is probably the first thing that springs to mind – but YouTube isn’t theonlyvideo-sharing platform out there! To ensure you have as many options as possible, we’ll be coveringthreedifferent ways that you can embed online videos, fromthreedifferent video-sharing platforms.

Article image

By the end of this article, you’ll know how to stream content from:

Although we’ll be sticking to YouTube, Dailymotion and Vimeo, you should be able to embed content fromanyvideo-sharing platform, using the platform’s own API or SDK, or Android’s WebView component. Just because your favorite video-sharing website isn’t included in this list, doesn’t mean you’re able to’t use the techniques discussed in this article!

Article image

Playing a video with VideoView

By adding a video to your application’s “res” directory, you can guarantee this video will always be accessible, regardless of whether the user has an active Internet connection. You should consider bundling a video with your application files, if the video in question is required to deliver a good user experience, or it provides part of your app’s core functionality.

Distributing videos as part of your application will also spare your users the overheads associated with downloading and buffering a video from the Internet, helping to preserve their device’s battery and data allowance.

Article image

Just be aware that adding video files to your applicationwillaffect the size of your APK, so you should take extra precautions toensure your APK doesn’t get out of control.

Displaying local videos, with VideoView

In this section, we’ll create an application that displays a video clip, which is stored locally in our application’s “res” directory.

We’ll display this video using Android’s VideoView class, and provide the user with a set of media controls, via Android’s MediaController class. The MediaController class includes play, pause, rewind and fast-forward controls, plus a progress slider that’ll allow the user to skip to a specific point within the video.

Article image

Getting started: Creating a “raw” directory

You’ll need to add the video file to your application’s “res/raw” directory. Android projects don’t contain this directory by default, so let’s create it now:

Android supports arange of video formats;you’re able to either use one of your own videos or download a compatible video from a website that offers free stock footage, such asSample Videos.

Once you have a video file, add it to your application by dragging and dropping it into the “raw” directory.

Add a VideoView to your UI

Next, we need to add a VideoView to our application’s user interface. This VideoView widget implements much of the basic behavior required to play a video.

In our VideoView widget, I’m setting both “layout_width” and “layout_height” to 0dp, as this allows the size of the VideoView to be calculated dynamically, based on the dimensions of the video we want it to display.

Loading and playing a video programmatically

Now, we need to retrieve the path to our local video; play the clip automatically at startup, and give the user a way to interact with the video.

1. Retrieve the video file

Open your project’s MainActivity class, and add a constant to represent the video file:

Next, define the URI that our VideoView widget should play, using the getMedia() and setVideoUri() methods:

We then need to create a getMedia() method that takes the name of the video file, in the form of a string, and then converts it into a URI object representing the path to this file:

Note that the string and returned URI don’t include the video’s extension.

2. Play the video

Next, we load the video each time onStart() is called, and set the video playing automatically, using the start() method:

3. Cleaning up

Playing a video puts significant strain on the system, so it’s important to release all the resources held by VideoView, as soon as they’re no longer required.

Since our app is fairly straightforward, we just need to stop the video and release all of its resources, but in more complicated applications this step might involve unregistering multiple listeners.

I’m going to create a releasePlayer() method, and call the stopPlayback() method on the VideoView:

We can then override the onStop() method and call releasePlayer():

Next, we need to tackle Android’s onPause() method.

Prior to Android 7.0, onPause() marked the end of the visual lifecycle, so you could start releasing resources as soon as your application entered a paused state. However, with the introduction of multi-window and picture-in-picture mode in Android 7.0, it’s possible for a paused application to remain visible onscreen, so you may need to continue playing the video, even when it’s in a paused state.

To ensure our app behaves correctly across all versions of Android, we need to perform a version check andonlypause VideoView in onPause() when our application is installed on Android Marshmallow or earlier.

4. Add playback controls

Currently, there’s no way for the user to pause, rewind or otherwise interact with the video, so we need to add some media controls, using Android’s MediaController class.

In the following snippet, we’re instantiating a MediaController programmatically, and then attaching it to our VideoView using setMediaPlayer(). Finally, we’re informing the VideoView about the new MediaController, using the setMediaController() method:

ViewView and MediaController: Completed code

After adding all the above to our MainActivity, your code should look something like this:

Testing your VideoView project

Install this project on your Android smartphone, tablet or Android Virtual Device (AVD). The video clip will start playing as soon as the application launches, but you can also control the video by tapping the VideoView widget, which reveals a set of media controls.

Once the MediaController is visible onscreen, you can play, pause, rewind and fast-forward the video, and jump to any point within the clip by dragging the MediaController’s progress bar.

How to embed YouTube videos in your Android app

Embedding a video file within your application is a great way to ensure that video is always available, regardless of the device’s Internet connection. However, embedding multiple large, high-resolution videos in your app is also a great way to increase the size of your APK!

If you’re concerned about APK size, or your application includes videos that are nice-to-have added extras, then you may want to publish those videos to an online platform and then stream them through your application at runtime.

When it comes to publishing videos online, there’s one website that instantly springs to mind, so in this section I’ll show you how to embedanyYouTube video in your app, using the YouTube Android Player API client library.

Retrieving a YouTube video’s ID

To start, you need to decide which YouTube video you want to display, and then retrieve its unique video ID.

you may use any YouTube video but I’m opting for “Android Authority’s Favorite Tech of 2018.” Load your chosen video and take a look at its URL in your browser’s address bar, for example the URL for the Android Authority video is:

youtube.com/watch?v=hJLBcViaX8Q

The ID is the part of the URL that uniquely identifies this video, which is the string of characters at the end of the URL (basically, everything after the “=” symbol). The video ID for the Android Authority video is:

hJLBcViaX8Q

Make a note of your video’s ID, as we’ll be using this later.

Get your project’s SHA-1 fingerprint

In order to access the YouTube Android Player API, you’ll need to generate an API key with Android restrictions. This involves linking the API key to your project’s unique package name and certificate fingerprint (SHA-1).

You can retrieve your project’s SHA-1 fingerprint, via the Gradle Console:

We’re using a debug certificate fingerprint, which is only suitable for testing an application. Before publishing an app, you should always generate a new API key based on that application’s release certificate.

Register with the Google API Console

Before you can use the YouTube Android Player API, you need to register your application in the Google API Console:

Download the YouTube Android Player API

Next, you’ll need to download the YouTube Android Player API client library. When using this library, it’s recommended that youenable ProGuard, to help keep your APK as lightweight as possible.

To add the YouTube library to your project:

Update your Manifest

If your application is going to displayanyonline video content, then it’ll need access to the Internet.

Open your project’s Manifest and add the Internet permission:

To give the user a taste of that cinematic, widescreen experience, I’m also setting MainActivity to launch in landscape mode:

Building the YouTube Player layout

You can display a YouTube video, using either:

I’ll be using YouTubePlayerView, so open your project’s “activity_main.xml” file, and add a YouTubePlayerView widget:

Implementing the YouTube Player

Next, open your MainActivity and complete the following tasks:

1. Extend YouTubeBaseActivity

Since we’re using a YouTubePlayerView in our layout, we need to extend YouTubeBaseActivity:

2. Initialize YouTube Player

We initialize the YouTube Player by calling initialize() and passing the API key we created earlier:

3. Implement onInitializationSuccess and onInitializationFailure

Finally, we need to specify how our application should react, depending on whether the initialization is a success, or a failure. If the YouTube Player is initialized successfully, then we can load our video, by passing the unique video ID:

Next, we need to tell our application how it should handle failed initializations. I’m going to display a Toast:

Playing a YouTube video: Completed code

Add all the above to your MainActivity, and you should end up with something like this:

Testing the YouTube Android Player API

You can test this application on either a physical Android smartphone or tablet, or an AVD. If you’re using an AVD, then make sure you’re using a system image that includes Google Play services. The YouTube app must also be installed on the AVD or physical Android device, as the YouTube API relies on a service that’s distributed as part of the YouTube for Android app.

Install the project on your device, and the YouTube video should start playing automatically, as soon as the application loads. If you tap the video, then you’ll have access to all the familiar YouTube controls that you can use to pause, play, fast-forward and rewind the video.

Display Dailymotion content in a WebView

When it comes to embedding videos in your Android app, there’s a wide range of video-sharing platforms that you can choose from, and some platforms have even produced SDKs dedicated to helping you interact with their content – including Dailymotion.

TheDailymotion Player SDK for Androidprovides a thin wrapper around Android’s WebView component, that makes it easier to embed Dailymotion videos in your applications.

In this section, I’ll show you how to stream any video from the Dailymotion website, using the third party Dailymotion Player SDK.

Get the Dailymotion video ID

Firstly, head over toDailymotion, find a video that you want to display, and then retrieve its video ID.

I’ll be usingthis time lapse video of fog, which has the following URL:

www.dailymotion.com/video/x71jlg3

The video’s ID is the unique string of characters at the end of its URL, so my video ID is: x71jlg3.

Adding the Dailymotion SDK

Since we’re using the Dailymotion SDK, we need to declare it as a project dependency. Open your project’s build.gradle file, and add the following:

When prompted, select “Sync Project with Gradle Files.”

Note that by default the Dailymotion SDK only gives you access to Dailymotion’s public data, such as a video’s title and description. you’re able to perform some additional tasks by registering your application with the Dailymotion platform, but since we just want to embed a video, we don’t need to worry about registering our application.

If you’re interesting in adding more Dailymotion functionality to your apps, then you’re able to learn your application with Dailymotion, over at the official docs.

Requesting Internet access

Once again, we’re streaming content from the World Wide Web, so our project requires the Internet permission:

Every Activity that displays Dailymotion content must have an “android:configChanges” attribute, so add the following to your MainActivity:

Adding Dailymotion’s PlayerWebView widget

The major component of the Dailymotion SDK is a PlayerWebView UI element, which provides a thin wrapper around Android’s WebView component.

We’ll be exploring WebViews in more detail in the following section, but WebViews essentially give you a way to embed web pages in your application. If we weren’t using the SDK’s specialized PlayerWebView, then we might use Android’s vanilla WebView component to display an entire Dailymotion web page within our application.

Instead, let’s add a PlayerWebView to our layout:

Configuring our Dailymotion PlayerWebView

Now we’ve implemented the PlayerWebView widget, we need to configure the player in our corresponding Activity class.

Open your MainActivity, and start by getting a reference to the PlayerWebView:

Then, call “dailyMotionPlayer.load” and pass it the video ID we retrieved earlier:

This gives us the following:

Install your project on a physical Android device or emulator, and your Dailymotion video should start playing automatically.

Embedding a Vimeo video

When it comes to embedding video content, you’ll typically want to use a platform-specific API or platform-specific SDK wherever possible. But, what if there isn’t an SDK or API available, for the video-sharing platform you have in mind?

In these scenarios, you may use Android’s WebView component to display the video as a web page that’s embedded in your Activity’s layout. In this final section, I’ll show you how to embed a video from the popular Vimeo platform, using a WebView.

In addition to displaying video content, WebViews can be useful in a number of other scenarios. For example, imagine you have some content that needs to be updated regularly; hosting that content online and then displaying it in your application via a WebView gives you the flexibility to change that content online at any time, without having to publish a new version of your app. However, just be cautious when using WebViews as they don’t support many of the features you’d typically expect from a stand-alone web browser. In particular, WebViews lack an address bar or navigational controls, which can make their content difficult for users to interact with.

Before using a WebView, you should always consider whether an alternative solution might be more appropriate, for example you could offload the content to the device’s default web browser, or implementChrome Custom Tabs.

Updating the Manifest

Since we’re streaming a video from the Internet, we need to add the Internet permission to our Manifest:

I’m also going to launch MainActivity in landscape mode:

Adding a WebView to our UI

Next, let’s add a WebView to our app. We can either add the WebView to our Activity’s layout, or turn the entire Activity into a WebView, by implementing it in our application’s onCreate() method.

I’m going to add a WebView to our application’s layout:

Choose your video

Once again, we need a video to display, but this time we’renotusing a video ID:

This code provides the following information:

I’m going to add this embed code to my project as a string, so you need to copy/paste this information into the following template:

Frustratingly, we need to make a few changes before the embed code is compatible with our Android app. First, we need to add a few “\” characters, so that Android Studio doesn’t complain about incorrect formatting:

Finally, the default video dimensions may be too large for some Android smartphone screens.In production, you’d typically experiment with various dimensions to see what delivers the best results, across as many different screen configurations as possible. However, to help keep this article from getting out of control, I’m just going to use the following, which should provide good results on your “typical” Android smartphone screen:

Displaying a web page in your Android app

Now we’ve created our layout and have our HTML all ready to go, open your MainActivity and lets implement our WebView.

Start by adding the HTML string:

Next, we need to load the above web page in our WebView, using the loadUrl() method:

JavaScript is disabled by default, so we’ll need to enable it in our WebView.

Every time you create a WebView, it’s automatically assigned a set of default WebSettings. We’ll retrieve this WebSettings object, using the getSettings() method, and then enable JavaScript, using setJavaScriptEnabled().

After adding all this to your MainActivity, your code should look something like this:

Testing your Vimeo app

You know the drill by now: install this project on a physical Android device or AVD. The WebView isn’t set to play automatically, so you’ll need to give the video a tap, to reveal Vimeo’s media controls. You can then play, pause, rewind and fast-forward the video, to make sure it’s functioning correctly.

Wrapping up

In this article, I showed you how to add YouTube, Vimeo and Dailymotion videos to your apps, using platform-specific APIs and SDKs, and Android’s own WebView component. I also showed you how to bundle a video file with your application, so it can be stored and played locally.

What’s your favourite way to display multimedia content to your users? Let us know in the comments below!

Thank you for being part of our community. Read ourComment Policybefore posting.