/api.video-android-player

The official Android player for api.video

Primary LanguageKotlinMIT LicenseMIT

badge   badge   badge

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 {
    implementation 'video.api:android-player:1.1.4'
}

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:

  1. Log into your account or create one here.
  2. Copy your API key (sandbox or production if you are subscribed to one of our plan).
  3. Go to the official api.video documentation.
  4. Log into your account in the top right corner. If it's already done, be sure it's the account you want to use.
  5. Go to API Reference -> Videos -> List all videos
  6. On the right, be sure the "Authentication" section contains the API key you want to use.
  7. Generate your upload token by clicking the "Try It!" button in the right section
  8. 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

  1. Add a ApiVideoExoPlayerView to your Activity/Fragment layout:
<video.api.player.ApiVideoExoPlayerView
    android:id="@+id/playerView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:show_fullscreen_button="true"
    app:show_controls="true"
    app:show_subtitles="true" />

You can also use an ExoPlayer StyledPlayerView or a SurfaceView according to your customisation level.

  1. 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")
    }
}
  1. 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
)
  1. 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:

  1. Click on the FloatingActionButton -> Settings
  2. 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].