api.video Android Live stream module

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

This library is an easy way to broadcast livestream to api.video platform on Android.

Getting started

Installation

Gradle

On build.gradle add the following code in dependencies:

dependencies {
    implementation 'video.api:android-live-stream:1.3.1'
}

Permissions


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

Your application must dynamically require android.permission.CAMERA and android.permission.RECORD_AUDIO.

Code sample

  1. Add permissions to your AndroidManifest.xml and request them in your Activity/Fragment.
  2. Add a ApiVideoView to your Activity/Fragment layout for the camera preview.

<video.api.livestream.views.ApiVideoView
    android:id="@+id/apiVideoView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. Implement a ConnectionChecker.
val connectionChecker = object : ConnectionChecker {
    override fun onConnectionSuccess() {
        //Add your code here
    }

    override fun onConnectionFailed(reason: String?) {
        //Add your code here
    }

    override fun onDisconnect() {
        //Add your code here
    }
}
  1. Creates an ApiVideoLiveStream instance.
class MyFragment : Fragment(), ConnectionChecker {
    private var apiVideoView: ApiVideoView? = null
    private lateinit var apiVideo: ApiVideoLiveStream

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val apiVideoView = view.findViewById(R.id.apiVideoView)
        val audioConfig = AudioConfig(
            bitrate = 128 * 1000, // 128 kbps
            sampleRate = 44100, // 44.1 kHz
            stereo = true,
            echoCanceler = true,
            noiseSuppressor = true
        )
        val videoConfig = VideoConfig(
            bitrate = 2 * 1000 * 1000, // 2 Mbps
            resolution = Resolution.RESOLUTION_720,
            fps = 30
        )
        apiVideo =
            ApiVideoLiveStream(
                context = getContext(),
                connectionChecker = this,
                initialAudioConfig = audioConfig,
                initialVideoConfig = videoConfig,
                apiVideoView = apiVideoView
            )
    }
}
  1. Start your stream with startStreaming method

For detailed information on this livestream library API, refers to API documentation.

Tips

You can check device supported configurations by using the helper: Helper

Documentation

Dependencies

We are using external library

PluginREADME
StreamPackREADME.md

Sample application

A demo application demonstrates how to use this livestream library. See /example folder.

FAQ

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

Was this page helpful?