To broadcast a live stream video, we have provided a convenient broadcaster tool called AmityStreamBroadcaster
. You will need to import AmityLiveVideoBroadcastKit.framework
into your app.
AmityStreamBroadcaster
requires the following permissions to work properly.
Camera access
Microphone access
Before using AmityStreamBroadcaster
, please make sure these permissions are already granted.
Here are the steps to ask for the permissions.
Add NSCameraUsageDescription
to your app's info.plist
.
Add NSMicrophoneUsageDescription
to your app's info.plist
.
Call AVCaptureDevice.requestAccess(for: .video, completion: ...)
Call AVAudioSession.sharedInstance().requestRecordPermission(_:)
You can create broadcaster instance by providing AmityClient
.
Before going live, you will need to set up the broadcaster session by creating AmityStreamBroadcasterConfiguration
. This configuration will be applied for the next live session.
The broadcaster object provides "preview view". After finish setting up the broadcaster, you then can take the preview view to attach into your screen.
You can set up video resolution anytime "before" going live. This setting will affect both the rendering of preview view, and the resolution of live stream session.
To begin broadcasting the live stream, call
To stop broadcasting the live stream, call
By default, the broadcaster will use the back camera. However, you can switch camera position anytime by calling
To observe a broadcaster state, we provide a delegate object that you can set to listen to broadcaster's events.
AmityStreamBroadcasterState
represents all the possible states.
.idle
indicates a state of stream in an idle state.
.connecting
indicates a state of stream that it's connecting to the stream server.
.connected
indicates a state of stream that it's connected to the stream server.
.disconnected
indicates a status of stream that it's disconnected.
The code below shows an example of printing out the state of broadcaster, when it changes.