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.
Table of contents
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
Permissions
In your AndroidManifest.xml
, add the following code in <manifest>
:
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
ApiVideoExoPlayerView
to your Activity/Fragment layout:
You can also use an ExoPlayer StyledPlayerView
or a SurfaceView
according to your customisation level.
- Implements the
ApiVideoPlayerController.Listener
interface:
val playerControllerListener = object : ApiVideoPlayerController.Listener {
override fun onError(error: Exception) {
Log.e(TAG, "An error happened", error)
}
override fun onReady() {
Log.I(TAG, "Player is ready")
}
}
- Instantiate the
ApiVideoPlayerController
in an your Activity/Fragment:
val playerView = findViewById<ApiVideoExoPlayerView>(R.id.playerView)
val player = ApiVideoPlayerController(
applicationContext,
VideoOptions("YOUR_VIDEO_ID", VideoType.VOD), // For private video: VideoOptions("YOUR_VIDEO_ID", VideoType.VOD, "YOUR_PRIVATE_VIDEO_TOKEN")
playerListener,
playerView
)
- Fullscreen video
If you requires a fullscreen video. You will have to implement the ApiVideoPlayerController.ViewListener
interface.
Check out for the implementation in the Sample application.
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].
Was this page helpful?