Broadcast Live Stream
To broadcast a live stream video, we provide a convenient broadcaster tool called AmityStreamBroadcaster
. We now only support 16:9 video ratio with the following resolution representing by the enum AmityStreamBroadcastResolution
:
.SD_480P
indicates a video with resolution 480x854 and video bitrate 1216 kpbs.HD_720P
indicates a video with resolution 720x1280 and video bitrate 2496 kpbs.FHD_1080P
indicates a video with resolution 1080x1920 and video bitrate 4992 kpbs
Setup
You simply need to include this dependency to your project in build.gradle
in the application level.
Inside your Application class, in the application initialization process, you need to register the video publisher SDK to the core SDK by calling.
We highly recommend using Android's ConstraintLayout to construct our AmityCameraView
Since we only support 16:9 video ratio, ConstratntLayout will ensure that the view will be drawn in the correct width and height.
Authorize the required permissions
AmityStreamBroadcaster
requires the following permissions to work properly.
As per the required parameter by the aforementioned object to provide AmityCameraView
, you will need to define the view in your Activity or Fragment layout by :
Camera access
Microphone access
Before using AmityStreamBroadcaster
, please make sure these permissions are granted.
See here the steps to ask for the permissions.
Create an AmityStreamBroadCaster Object
In order to create the object, we also provide the AmityStreamBroadCaster.Builder
class to create and configure this object easily. It requires AmityCameraView
as a parameter and AmityStreamBroadcasterConfig
as a configurable value which will be explained in the following section.
Prepare a configuration
For configuration, we provide the AmityStreamBroadcasterConfiguration.Builder
to construct the configuration conveniently. As we have mentioned above, We support SD_480P
, HD_720P
and, FHD_1080P
resolutions. Orientations are relying on Android Configuration class, you may either choose Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE
.
Setup a layout
As per the required parameter by the aforementioned object to provide AmityCameraView
, you need to define the view in your Activity or Fragment layout by :
We highly recommend using Android's ConstraintLayout to construct our AmityCameraView
Since we only support 16:9 video ratio, ConstraintLayout ensures that the view will be drawn in the correct width and height.
Setup a layout in Jetpack Compose
In Jetpack Compose, inflate AmityCameraView
as AndroidView and provide it to aforementioned object as below
Preview the video
To begin previewing the camera input call
Start live stream session
To begin broadcasting live stream call
Stop live stream session
To stop broadcasting live stream call
Switch camera position
By default, the broadcaster will use the back camera. However, you can switch camera position anytime by calling.
Observe a broadcasting state
To observe the status of a broadcast, we provide a function (flow) to observe any status changes and return as AmityStreamBroadcasterState
. The possible statuses are :
.IDLE
indicates a status of stream in an idle state..CONNECTING
indicates a status of stream that it's connecting to a rtmp server..CONNECTED
indicates a status of stream that it's connected to a rtmp server..DISNNECTED
indicates a status of stream that it's disconnected to a rtmp server. We also provide error information through an exception.
Last updated