Android Kotlin SDK

Android Kotlin SDK API.VIDEO

The api.video service helps you put video online without the hassle. This documentation helps you use the corresponding Android client. This is an early version, feel free to report any issue.

Installation

We are using exernal library for rtmp brodcasting witch using jitpack.io as dependency manager, so first of all add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Now you can use Maven or Jitpack.io.

With maven

On build.gradle add the following code in dependencies:

dependencies {
    ...
    implementation 'video.api:android-kotlin-sdk:0.1.7' // add this line
}

With jitpack.io

On build.gradle add the following code in dependencies:

dependencies {
    ...
    implementation 'com.github.apivideo:android-kotlin-sdk:0.1.7' // add this line
}

Or import with a local aar

  1. Download the latest release of the aar file.
  2. Go to “File” > “Project Structure...”
  3. On "Modules" select the "+" button and select "Import .JAR/.AAR Package" then click "next"
  4. Select the AAR file you have just downloaded, and click "Finish"
  5. Then go to "Dependencies" select the the app module and add a new dependencies by clicking on the "+" button, then select "Module Dependency"
    (if there is no "Module Dependency", close the window and re-open it, it should be fine)
  6. select Api.Video module, click "ok"
  7. click on "Apply" and then "ok"

Permissions:

<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
</manifest>

Application:

<application
    ...
    android:largeHeap="true">
    ...
</application>

Quick Start

1. In the App instantiate a new Client

  • If you want to use the production environment, use createProduction method
  • If you want to use the sandbox environment , use createSandbox method
private val apiVideoClient = Client.createSandbox(« YOUR_SANDBOX_API_KEY »)

2. In your MainActivity.kt file import the sdk

3. Get the Client variable

var client = (application as? App)?.getApiVideoClient()

4. Create and upload a video file


client.videos.upload(file, video, object : CallBack<Video>{
    override fun onError(error: SdkResponse) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Video) {
        // response is Video Object
    }
})

FULL API

Client

Create Production Environment

// YOUR_PRODUCTION_API_KEY: String
val apiVideoClient = Client.createProduction(YOUR_PRODUCTION_API_KEY)

Create Sandbox Environment

// YOUR_SANDBOX_API_KEY: String
val apiVideoClient = Client.createSandbox(YOUR_SANDBOX_API_KEY)

VIDEO

Upload Video

To upload a large video file don't forget to add 'android:largeHeap="true"' on your Android Manifest

Getting started
// file: File
val file = File("test.mp4")
client.videos.upload(file, object : CallBack<Video>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Video) {
        // response is Video Object
    }
})
Option 2
// file: File
// video: Video
val file = File("test.mp4")
val video = Video("test title")
client.videos.upload(file, video, object : CallBack<Video>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Video) {
        // response is Video Object
    }
})
Option 3
// file: File
// title: String
val file = File("test.mp4")
val title = "test title"
client.videos.upload(file, title, object : CallBack<Video>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Video) {
        // response is Video Object
    }
})

Get List of Video

Option 1
// pageNumber: Int,
// pageSize: Int,
// params: QueryParams,
client.videos.list(pageNumber, pageSize, params, object : CallBack<Page<Video>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Page<Video>?) {
        // response is Page<Video>
    }
})
Option 2
// pageNumber: Int,
// params: QueryParams
client.videos.list(pageNumber, params, object : CallBack<Page<Video>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Page<Video>?) {
        // response is Page<Video>
    }
})
Option 3
// pageNumber: Int,
// pageSize: Int

client.videos.list(pageNumber, pageSize, object : CallBack<Page<Video>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Page<Video>?) {
        // response is Page<Video>
    }
})
Option 4
// pageNumber: Int,
client.videos.list(pageNumber, object : CallBack<Page<Video>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Page<Video>?) {
        // response is Page<Video>
    }
})

Get Video By Id

// videoId: String
client.videos.get(videoId, object : CallBack<Video>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
    
    override fun onResponse(response: Video) {
        // response is Video
    }
})

Get Video Status

// videoId: String
client.videos.getStatus(videoId, object : CallBack<Status>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
    
    override fun onResponse(response: Status) {
        // response is Status
    }
})

Update Video

// video: Video
client.videos.update(video, object : CallBack<Video>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
    
    override fun onResponse(response: Video) {
        // response is Video
    }
})

Upload Video Thumbnail

// videoId: String,
// file: File
client.videos.uploadThumbnail(videoId, file, object : CallBack<Video>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
    
    override fun onResponse(response: Video) {
        // response is Video
    }
})

Delte Thumbnail

// videoId: String,
client.videos.deleteThumbnail(videoId, object : CallBack<Video>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
    
    override fun onResponse(response: Video) {
        // response is Video
    }
})

Delete Video

// videoId: String
client.videos.delete(videoId, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
    
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

PLAYER

Create Player


// player: Player
client.players.create(player, object : CallBack<Player>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }

    override fun onResponse(response: Player) {
        // response is Player
    }
})

Update Player

// player: Player
client.players.update(player, object : CallBack<Player>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                              
    override fun onResponse(response: Player) {
        // response is Player
    }
})

Get All Players

Option 1
// pageNumber: Int,
// pageSize: Int,
// params: QueryParams,
client.players.list(pageNumber, pageSize, params, object : CallBack<Page<Player>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                             
    override fun onResponse(response: Page<Player>?) {
        // response is Page<Player>
    }
})
Option 2
// pageNumber: Int,
// params: QueryParams,
client.players.list(pageNumber, params, object : CallBack<Page<Player>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                             
    override fun onResponse(response: Page<Player>?) {
        // response is Page<Player>
    }
})
Option 3
// pageNumber: Int,
// pageSize: Int,
client.players.list(pageNumber, pageSize, object : CallBack<Page<Player>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                             
    override fun onResponse(response: Page<Player>?) {
        // response is Page<Player>
    }
})
Option 4
// pageNumber: Int,
client.players.list(pageNumber, object : CallBack<Page<Player>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                             
    override fun onResponse(response: Page<Player>?) {
        // response is Page<Player>
    }
})

Get Player Id

// playerId: String
client.players.get(playerId, object : CallBack<Player>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                   
    override fun onResponse(response: Player) {
        // response is Player
    }
})

Delete Player

// playerId: String
client.players.delete(playerId, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                           
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

Upload Logo Player

// playerId: String,
// file: File,
// link: HttpUrl,
client.players.uploadLogo(playerId, file, link, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                           
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

LIVESTREAM

Create Live Stream

Option 1
// liveStream: LiveStream
client.liveStreams.create(liveStream, object : CallBack<LiveStream>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                            
    override fun onResponse(response: LiveStream) {
        // response is LiveStream
    }
})
Option 2
// name: String
client.liveStreams.create(name, object : CallBack<LiveStream>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                            
    override fun onResponse(response: LiveStream) {
        // response is LiveStream
    }
})

Get LiveStream By Id

// liveStreamId: String
client.liveStreams.get(liveStreamId, object : CallBack<LiveStream>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                               
    override fun onResponse(response: LiveStream) {
        response as LiveStream
    }
})

Get All LiveStream

Option 1
// pageNumber: Int,
// pageSize: Int,
// params: QueryParams,
client.liveStreams.list(pageNumber, pageSize, params, object : CallBack<Page<LiveStream>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                  
    override fun onResponse(response: Page<LiveStream>?) {
        // response is Page<LiveStream>
    }
})
Option 2
// pageNumber: Int,
// params: QueryParams,
client.liveStreams.list(pageNumber, params, object : CallBack<Page<LiveStream>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                  
    override fun onResponse(response: Page<LiveStream>?) {
        // response is Page<LiveStream>
    }
})
Option 3
// pageNumber: Int,
// pageSize: Int,
client.liveStreams.list(pageNumber, pageSize, object : CallBack<Page<LiveStream>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                  
    override fun onResponse(response: Page<LiveStream>?) {
        // response is Page<LiveStream>
    }
})
Option 4
// pageNumber: Int,
client.liveStreams.list(pageNumber, object : CallBack<Page<LiveStream>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                  
    override fun onResponse(response: Page<LiveStream>?) {
        // response is Page<LiveStream>
    }
})

Delete Live Stream

// liveStreamId: String
client.liveStreams.delete(liveStreamId, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                       
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

Upload Thumbnail Live Stream

// liveStreamId: String,
// file: File
client.liveStreams.uploadThumbnail(liveStreamId, file, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                       
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

Delete Thumbnail Live Stream

// liveStreamId: String,
client.liveStreams.deleteThumbnail(liveStreamId, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                       
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

Start and Stop Live Stream

// liveStream: LiveStream
// surfaceView : SurfaceView
// context: Context
// connectChecker: ConnectCheckerRtmp
class MyClass: ConnectCheckerRtmp {
    RtmpStreamer.Builder()
        .videoQuality(RtmpStreamer.Quality.QUALITY_1080)
        .videoFps(30)
        .build()
        .start(
            liveStream,
            surfaceView,
            context,
            connectChecker
        )
// override all methodes 

}

CHAPTER

Upload Chapter

// videoId: String,
// language: Locale,
// file : File
client.chapters.upload(videoId,language, file, object : CallBack<Chapter>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                     
    override fun onResponse(response: Chapter) {
        // response is Chapter
    }
})

Get Chapter

// videoId: String
// language: Locale
client.chapters.get(videoId, language, object : CallBack<Chapter>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                    
    override fun onResponse(response: Chapter) {
        // response is Chapter
    }
})

Get All Chapters

Option 1
// videoId: String,
// pageNumber: Int,
// pageSize: Int
client.chapters.list(videoId, pageNumber, pageSize, object : CallBack<Page<Chapter>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                            
    override fun onResponse(response: Page<Chapter>?) {
        // response is Page<Chapter>
    }
})
Option 2
// videoId: String,
// pageNumber: Int,
client.chapters.list(videoId, pageNumber, object : CallBack<Page<Chapter>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                            
    override fun onResponse(response: Page<Chapter>) {
        // response is Page<Chapter>
    }
})

Delete Chapter

// videoId: String
// language: Locale
client.chapters.delete( videoId, language, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                      
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

CAPTION

Upload Caption

// videoId: String
// language: Locale
// file: File
client.captions.upload( videoId, language, file, object : CallBack<Caption>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    override fun onResponse(response: Caption) {
        // response is Caption
    }
})

Get Caption

// videoId: String
// language: Locale
client.captions.get( videoId, language, object : CallBack<Caption>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    override fun onResponse(response: Caption) {
        // response is Caption
    }
})

Get All Captions

Option 1
// videoId: String,
// pageNumber: Int,
// pageSize: Int,
client.captions.list(videoId,pageNumber, pageSize, object : CallBack<Page<Caption>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    override fun onResponse(response: Page<Caption>?) {
        // response is Page<Caption>
    }
})
Option 2
// videoId: String,
// pageNumber: Int,
client.captions.list(videoId,pageNumber, object : CallBack<Page<Caption>?>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    override fun onResponse(response: Page<Caption>?) {
        // response is Page<Caption>
    }
})

Update Default Value

// videoId: String
// language: Locale
client.captions.setDefault(videoId, language, object : CallBack<Caption>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    override fun onResponse(response: Caption) {
        // response is Caption
    }
})

Delete Caption

// videoId: String
// language: Locale
client.captions.delete(videoId, language, object : CallBack<Boolean>{
    override fun onError(error: Error) {
        Log.e("error", error.toString())
    }

    override fun onFatal(e: IOException) {
        throw e
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
    override fun onResponse(response: Boolean) {
        // response is Boolean
    }
})

Plugins

API.Video sdk is using external library

PluginREADME
rtmp-rtsp-stream-client-javahttps://github.com/pedroSG94/rtmp-rtsp-stream-client-java

FAQ

If you have any questions, ask us here: https://community.api.video .
Or use Issues.

License

MIT License
Copyright (c) 2020 api.video


Did this page help you?