Android Kotlin live stream module

api.video Android Kotlin Livestream library

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

Installation

Gradle

On build.gradle add the following code in dependencies:

dependencies {
        ...
        implementation 'video.api:android-livestream:0.3.0'
}

Sample

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

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.

Getting Started

  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"
    app:aspectRatioMode="adjust"
    app:isFlipHorizontal="false"
    app:isFlipVertical="false"
    app:keepAspectRatio="true" />
  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
    }

    override fun onAuthError() {
        //Add your code here
    }

    override fun onAuthSuccess() {
        //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 * 1024, // 128 kbps
            sampleRate = 48000,
            stereo = true,
            echoCanceler = true,
            noiseSuppressor = true
        )
        val videoConfig = VideoConfig(
            bitrate = 2 * 1024 * 1024, // 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.

Documentation

Dependencies

We are 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?