# Live Streaming

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

Video SDK sessions can be live streamed to an unlimited audience using Real-Time Messaging Protocol (RTMP). This is helpful if you need to scale Video SDK attendees beyond the 1,000 real-time session user limit. For example, you can live stream to [YouTube Live](https://developers.google.com/youtube/v3/live/guides/rtmps-ingestion), [Facebook Live](https://www.facebook.com/help/755943624557739), [Twitch](<https://dev.twitch.tv/docs/video-broadcast/#:~:text=The%20tool%20sends%20a%20video,Time%20Messaging%20Protocol%20(RTMP).>), [AWS IVS](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/streaming-config.html#streaming-config-settings), and other services.

See the following for how to set up a streaming event in a third-party platform and implement a feature to start and stop live streaming of a session using the Video SDK.

## Retrieve credentials

Live streaming with SDKs requires the following information from third-party streaming platforms: Stream URL, Stream Key, Broadcast URL. See [Live stream to YouTube](#live-stream-to-youtube) for an example.

## Start live streaming

To start live streaming a session from your app, first obtain an instance of `ZMVideoSDKLiveStreamHelper` and verify that the current user can start streaming. Then call `startLiveStream` within `ZMVideoSDKLiveStreamHelper` to begin live streaming.

```swift
// Get the ZMVideoSDKLiveStreamHelper to perform live stream actions.
if let liveStreamHelper = ZMVideoSDK.shared()?.getLiveStreamHelper() {
    // Check if the live stream can start.
    if liveStreamHelper.canStartLiveStream() == ZMVideoSDKErrors_Success {
        // Call startLiveStream to begin the live stream.
        let liveStreamStartReturnValue = lliveStreamHelper.startLiveStream(streamingURL, broadcastUrl: broadcastURL, liveStreamKey: streamingKey)
        switch liveStreamStartReturnValue {
        case ZMVideoSDKErrors_Success:
            // Live stream successfully began.
            break
        case ZMVideoSDKErrors_Meeting_Live_Stream_Error:
            // Live stream could not start.
            break
        default:
            break
        }
    }
}
```

```objectivec
// Get the ZMVideoSDKLiveStreamHelper to perform live stream actions.
ZMVideoSDKLiveStreamHelper *liveStreamHelper = [[ZMVideoSDK sharedVideoSDK] getLiveStreamHelper];
// Check if the live stream can start.
if ([liveStreamHelper canStartLiveStream] == ZMVideoSDKErrors_Success) {
    // Call startLiveStreamWithStreamingURL to begin the live stream.
    ZMVideoSDKErrors liveStreamStartReturnValue = [liveStreamHelper startLiveStream:streamURL broadcastUrl:broadcastURL liveStreamKey:streamingKey];
    switch (liveStreamStartReturnValue) {
        case ZMVideoSDKErrors_Success:
            // Live stream successfully began.
            break;
        case ZMVideoSDKErrors_Meeting_Live_Stream_Error:
            // Live stream could not start.
            break;
        default:
            break;
    }
}
```

## Stop live streaming

To stop the stream using the SDK, call the `stopLiveStream` method.

```swift
// Get the ZMVideoSDKLiveStreamHelper to perform livestream actions.
if let liveStreamHelper = ZMVideoSDK.shared()?.getLiveStreamHelper() {
    // Call stopLiveStream to stop the live stream.
    liveStreamHelper.stopLiveStream()
}
```

```objectivec
// Get the ZMVideoSDKLiveStreamHelper to perform livestream actions.
ZMVideoSDKLiveStreamHelper *liveStreamHelper = [[ZMVideoSDK sharedVideoSDK] getLiveStreamHelper];
// Call stopLiveStream to stop the live stream.
[liveStreamHelper stopLiveStream];
```

## Listen for updates

After calling the `startLiveStream` function, listen for updates through your `ZMVideoSDKDelegate` implementation's `onLiveStreamStatusChanged` callback.

| Name                                    | Description                    |
| --------------------------------------- | ------------------------------ |
| `ZMVideoSDKLiveStreamStatus_None`       | No live stream is active.      |
| `ZMVideoSDKLiveStreamStatus_InProgress` | Live streaming is in progress. |
| `ZMVideoSDKLiveStreamStatus_Ended`      | Live streaming has ended.      |

### Get notified when a user starts or stops live streaming

```swift
func onLiveStreamStatusChanged(_ liveStreamHelper: ZMVideoSDKLiveStreamHelper!, liveStreamStatus status: ZMVideoSDKLiveStreamStatus) {
    // Use helper to perform live stream actions.
    // Status is the new live stream status.
    switch status {
    case ZMVideoSDKLiveStreamStatus_InProgress:
        print("Live stream now in progress.")
    case ZMVideoSDKLiveStreamStatus_Ended:
        print("Live stream has ended.")
    default:
        print("Live stream status unknown.")
    }
}
```

```objectivec
- (void)onLiveStreamStatusChanged:(ZMVideoSDKLiveStreamHelper*)liveStreamHelper liveStreamStatus:(ZMVideoSDKLiveStreamStatus)status {
    // Use helper to perform live stream actions.
    // Status is the new live stream status.
    switch (status) {
        case ZMVideoSDKLiveStreamStatus_InProgress:
            NSLog(@"Live stream now in progress.");
            break;
        case ZMVideoSDKLiveStreamStatus_Ended:
            NSLog(@"Live stream has ended.");
        default:
            NSLog(@"Live stream status unknown.");
            break;
    }
}
```

## Live stream to YouTube

For instance, if you want to live stream a session to YouTube, you must [enable live streaming](https://support.google.com/youtube/answer/9227509?hl=en) on your Google account.

### Step 1:

Login to YouTube. Locate the video icon and press "Go Live".

![Go Live option on YouTube](/img/1569946554166.png)

### Step 2:

Click the Stream button in the top panel. **Note: YouTube Webcam services are not compatible with Zoom SDK**.

![YouTube Stream button](/img/1569946563191.png)

### Step 3:

Fill out the required information and toggle "Schedule for later". If this is not selected, the live stream will start immediately and will not provide setting info.

![YouTube settings for Schedule for Later](/img/1569946580691.png)

### Step 4:

After creating the stream, the Steam URL and Stream Key will be available.

![YouTube Stream URL and Key setup](/img/1569946642209.png)

### Step 5:

Click the share button beside your account icon to get the broadcast URL.

![YouTube broadcast URL](/img/vsdk-ios-youtube-broadcastURL.png)

_Use the [YouTube Live Streaming API](https://developers.google.com/youtube/v3/live/getting-started) to automate these steps and get stream information programmatically._
