Control live streams with GoCoder SDK for iOS

Learn how to start, stop, and monitor a live stream broadcast with Wowza GoCoder™ SDK for iOS.

Before you begin


Before adding the functionality below to an app, make sure you've set up the Wowza GoCoder SDK for your project:

  • Request a free license and download the latest version of the SDK.
  • Configure your Xcode project to use the SDK.

See Download and install GoCoder SDK for iOS for detailed instructions.


Start streaming


Use the startStreaming method in the WowzaGoCoder class to initiate a live stream.

//Make sure streaming isn't already active
if (!self.goCoder.isStreaming)
  // Start the live stream
  [self.goCoder startStreaming:statusCallback];

Note: If you start a broadcast and get the message, "Limited Bandwidth," it means you're using a bitrate that's too large for the current network conditions. The broadcaster will start buffering frames to preserve the quality of the playback and any recordings, but this will increase playback latency. To minimize latency, try using a lower bitrate instead.

Stop streaming


Use the endStreaming method in the WowzaGoCoder class to stop a live stream.

if (self.goCoder.isStreaming)
  // Stop the live stream
  [self.goCoder endStreaming:statusCallback];

Monitor the status of the live stream


Use the statusCallback argument for the startStreaming and endStreaming methods to implement the WOWZStatusCallback interface. This interface defines the following callbacks that are invoked for a live stream broadcast:

Property Description
WOWZStateIdle The stream is inactive. This is the state before and after the broadcast.
WOWZStateStarting The audio and video inputs are initializing and connecting to a Wowza Streaming Engine server or to the Wowza Streaming Cloud live stream.
WOWZStateRunning The broadcast is streaming.
WOWZStateStopping The streaming connection is closing. After the connection closes, the broadcast state returns to WOWZStateIdle.

The following example shows successful state transitions as well as an error:

//
// Methods implemented for the WOWZStatusCallback protocol
//

// A successful status transition has been reported by the GoCoder SDK  
- (void) onSuccess:(WZStatus *) goCoderStatus {
    switch (goCoderStatus.state) {
  case WOWZStateIdle:
      NSLog(@"SDK State: %@",
    "There is no active streaming broadcast session");
      break;

  case WOWZStateStarting:
      NSLog(@"SDK State: %@",
    "A streaming broadcast session is starting up");
      break;

  case WOWZStateRunning:
      NSLog(@"SDK State: %@",
    "A streaming broadcast session is running");
      break;

  case WOWZStateStopping:
      NSLog(@"SDK State: %@",
    "A streaming broadcast session is shutting down");
      break;
    }
}

// If an error is reported by the GoCoder SDK, display an alert
// that contains the error details using the U/I thread
- (void) onWOWZError:(WOWZStatus *) goCoderStatus {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Live Streaming Error"
            message:self.goCoder.status.description
            preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
            handler:^(UIAlertAction * action) {}];
        
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
        
    });
}

More resources