The official Android player for api.video
api.video Android player
api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.
Project description
Easily integrate a video player for videos from api.video in your Android application.
Getting started
Installation
Gradle
In your module build.gradle
, add the following code in dependencies
:
dependencies {
implementation 'video.api:android-player:1.0.0'
}
Permissions
In your AndroidManifest.xml
, add the following code in <manifest>
:
<uses-permission android:name="android.permission.INTERNET" />
Retrieve your video Id
At this point, you must have uploaded a least one video to your account. If you haven’t see how to upload a video. You’ll need a video Id to use this component and play a video from api.video. To get yours, follow these steps:
- Log into your account or create one here.
- Copy your API key (sandbox or production if you are subscribed to one of our plan).
- Go to the official api.video documentation.
- Log into your account in the top right corner. If it’s already done, be sure it’s the account you want to use.
- Go to API Reference -> Videos -> List all videos
- On the right, be sure the “Authentication” section contains the API key you want to use.
- Generate your upload token by clicking the “Try It!” button in the right section
- Copy the “videoId” value of one of elements of the response in the right section.
Alternatively, you can find your video Id in the video details of your dashboard.
Code sample
- Add a
StyledPlayerView
to your Activity/Fragment layout:
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/playerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:show_subtitle_button="true" />
You can customize the StyledPlayerView
according to your application design.
- Implements the
Player.Listener
interface:
val playerListener = object : ApiVideoPlayer.Listener {
override fun onError(error: Exception) {
Log.e(TAG, "An error happened", error)
}
override fun onReady() {
Log.I(TAG, "Player is ready")
}
}
- Instantiate the
ApiVideoPlayer
in an your Activity/Fragment:
val playerView = findViewById<StyledPlayerView>(R.id.playerView)
val player = ApiVideoPlayer(
this,
"YOUR_VIDEO_ID",
VideoType.VOD,
playerListener,
playerView
)
Sample application
A demo application demonstrates how to use player.
See /example
folder.
On the first run, you will have to set your video Id:
- Click on the FloatingActionButton -> Settings
- Replace “YOUR_VIDEO_ID” by your video Id
Documentation
Dependencies
We are using external library
Plugin | README |
---|---|
Exoplayer | README.md |
FAQ
If you have any questions, ask us here: https://community.api.video. Or use [Issues].