How to live stream with Wowza GoCoder SDK for iOS

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

Contents


Start streaming
Stop streaming
Monitor the status of the live stream

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];

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 WZStatusCallback interface. This interface defines the following callbacks that are invoked during the lifetime of a live stream broadcast:

Status code Description
WZStateIdle The stream is inactive. This is the status before and after the broadcast.
WZStateStarting The audio and video inputs are initializing and connecting to a Wowza Streaming Engine server or the Wowza Streaming Cloud service.
WZStateRunning The broadcast is actively streaming.
WZStateStopping The streaming connection is closing. After the connection closes, the broadcast status returns to WZStateIdle.

The following example demonstrates successful status transitions as well as an error status.

//
// Methods implemented for the WZStatusCallback protocol
//

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

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

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

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

// If an error is reported by the GoCoder SDK, display an alert
// dialog containing the error details   
- (void) onError:(WZStatus *) goCoderStatus {
    // Run this on the U/I thread
    dispatch_async(dispatch_get_main_queue(), ^{
  UIAlertView *alertDialog =
      [[UIAlertView alloc] initWithTitle:@"Live Streaming Error"
        message:goCoderStatus.description
        delegate:nil
    cancelButtonTitle:@"OK"
    otherButtonTitles:nil];
  [alertDialog show];    
    });
}

If you're having problems or want to discuss this article, post in our forum.