Tutorials · 3 min read

Switch your Android player to api.video

Switch your existing Android player to api.video

If you've developed an existing Android application with a video player, you may be looking for ways to enhance the video playback experience for your users.

Thibault Beyou

February 15, 2023

If you've developed an existing Android application with a video player, you may be looking for ways to enhance the video playback experience for your users. One solution to consider is using api.video player: customizable design, advanced playback features, and easy integration.

This tutorial will demonstrate how to easily use your player to play video from api.video.

Let’s go! ▶️

Before getting started

To help you migrate your video content to api.video, we’ve built a tool that allows you to quickly and easily import your videos from another provider (e.g. Dropbox or Vimeo) to your api.video dashboard. All you need is an API key and the provider’s access token. You can get started with a few clicks.

Extensions

In this tutorial, we will often talk about extensions. If you are not familiar with the concept of extensions, let me explain: it is a way to extend a class or an interface with new functionality. And… it is a kind of magic 🪄

Here is a quick example:

kotlin

Then, you can use it as a regular property:

kotlin

Installation

In your module build.gradle, add

javascript

where X.X.X is the latest version of api.video Android player.

Video Options

On api.video, each video is identified by a unique identifier called video Id. You can find the video Id in the dashboard or in the video list. In this tutorial, replace YOUR_VIDEO_ID with the video Id of your video.

To set an api.video video Id, you have to pass it through a VideoOptions instance:

kotlin

If you are using private videos you will also have to pass the private token.

A private token is a unique token that can be used only once to access a specific private video.

kotlin

Then, to simplify migration, we have made some specific extensions for 3 main Android players:

  • ExoPlayer
  • VideoView
  • MediaPlayer

Extensions for ExoPlayer

ExoPlayer provides 2 main ways to play a video on your ExoPlayer instance:

  • addMediaSource or addMediaItem: adds the video to the playlist
  • setMediaSource or setMediaItem: clears the playlist and adds the video

With the api.video Android player Exoplayer extensions, you can directly use these methods with a VideoOptions method.

kotlin

Extensions for VideoView

The api.video Android player provides extensions to play a new video with a VideoView:

kotlin

Extensions for MediaPlayer

The api.video Android player provides extensions to play a new video with a MediaPlayer:

kotlin

Private video

The extension will send a request for the private videos to get the token session. If this request fails, the error will be returned in the onError callback of the previous methods.

If you want to check that no error has happened, write:

kotlin

Conclusion

Let’s go. Let’s play video from api.video from your own Android video player now 🎉🎉🎉🎉

 

To start using api.video for your videos, sign-up for a free sandbox account now.

Try out more than 80 features for free

Access all the features for as long as you need.
No commitment or credit card required

Video API, simplified

Fully customizable API to manage everything video. From encoding to delivery, in minutes.

Built for Speed

The fastest video encoding platform. Serve your users globally with 140+ points of presence. 

Let end-users upload videos

Finally, an API that allows your end-users to upload videos and start live streams in a few clicks.

Affordable

Volume discounts and usage-based pricing to ensure you don’t exceed your budget.