api.video-android-live-stream icon indicating copy to clipboard operation
api.video-android-live-stream copied to clipboard

Android RTMP live stream client. Made with ♥ by api.video

badge   badge   badge

Android RTMP live stream client

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

  • Table of contents
  • Project description
  • Getting started
    • Installation
      • Gradle
    • Permissions
    • Code sample
  • Tips
  • Documentation
  • Dependencies
  • Sample application
  • FAQ

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.4.2'
}

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 IConnectionListener.
val connectionListener = object : IConnectionListener {
    override fun onConnectionSuccess() {
        //Add your code here
    }

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

    override fun onDisconnect() {
        //Add your code here
    }
}
  1. Create an ApiVideoLiveStream instance.
class MyFragment : Fragment(), IConnectionListener {
    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(),
                connectionListener = 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

Plugin README
StreamPack README.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.