Go Live On Social Media - iOS
This feature lets a participant broadcast the room on social media platforms such as Facebook or YouTube. This guide shows how a participant can start and stop broadcasting the room.
- Start LiveStream - By using
startLivestream()function, a participant can start broadcasting the room on various platforms by providing the URL and stream key of each platform. - Stop LiveStream - By using
stopLivestream()function, a participant can stop broadcasting on all platforms.
Both methods are async throws. Call them with try await inside a Task, after you join the room. When a call fails, it throws a VideoSDKError.
Start And Stop Live Stream
- Swift
/// keep track of livestream
private var livestreamStarted = false
@IBAction func livestreamButtonTapped(_ sender: Any) {
Task {
do {
if !livestreamStarted {
// prepare output
// specify social-media-url and stream-key
let output = LivestreamOutput(url: "<rtmp://a.rtmp.youtube.com/live2>", streamKey: "<stream-key>")
// start livestream
try await self.room?.startLivestream(outputs: [output])
}
else {
// stop livestream
try await self.room?.stopLivestream()
}
} catch {
print("Livestream request failed: \(error)")
}
}
}
Events
-
onLivestreamStarted - Whenever broadcasting of the room started,
onLivestreamStartedevent will trigger. -
onLivestreamStopped - Whenever broadcasting of the room stopped,
onLivestreamStoppedevent will trigger.
- Swift
/// Called after livestream starts
func onLivestreamStarted() {
livestreamStarted = true
// show indication that livestream is started
}
/// Called after livestream stops
func onLivestreamStopped() {
livestreamStarted = false
// hide livestream indication
}
Got a Question? Ask us on discord

