The WowzaGoCoder
class provides the methods for starting and stopping the live stream. The startStreaming
method is used to initiate a live stream.
//Make sure streaming isn't already active
if (!self.goCoder.isStreaming)
// Start the live stream
[self.goCoder startStreaming:statusCallback];
//Make sure streaming isn't already active
if (!this.goCoder.isStreaming()) {
// Validate the current broadcast config
WZStreamingError configValidationError = this.goCoder.getConfig().validateForBroadcast();
if (configValidationError != null) {
WZLog.error(configValidationError);
} else {
// Start the live stream
this.goCoder.startStreaming(statusCallback);
}
}
The endStreaming
method is used to stop a live stream.
if (self.goCoder.isStreaming)
// Stop the live stream
[self.goCoder endStreaming:statusCallback];
if (this.goCoder.isStreaming()) {
// Stop the live stream
this.goCoder.endStreaming(statusCallback);
}
The statusCallback
argument for startStreaming
and endStreaming
is an object that implements the WZStatusCallback
interface. This interface defines a set of callbacks that will be invoked during the lifetime of a live streaming broadcast. The lifecycle stages of a broadcast are defined below:
Status Code | Description |
---|---|
WZStateIdle |
Streaming is not active (i.e. before or after a broadcast) |
WZStateStarting |
The audio and video inputs (e.g. the camera) and the streaming connection are being initialized. |
WZStateRunning |
The broadcast is active and streaming. |
WZStateStopping |
The streaming connection is being closed. Once the connection is closed the broadcast status will be returned to WZStateIdle . |
//
// 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];
});
}
Status Code | Description |
---|---|
WZState.IDLE |
Streaming is not active (i.e. before or after a broadcast) |
WZState.STARTING |
The audio and video inputs (e.g. the camera) and the streaming connection are being initialized. |
WZState.READY |
Indicates that the audio and video inputs and the streaming connection have been successfully initialized. |
WZState.RUNNING |
The broadcast is active and streaming. |
WZState.STOPPING |
The streaming connection is being closed. Once the connection is closed the broadcast status will be returned to WZState.IDLE . |
//
// Methods implemented for the WZStatusCallback interface
//
// A successful status transition has been reported by the GoCoder SDK
WZStatusCallback statusCallback = new WZStatusCallback() {
@Override
public void onSuccess(final WZStatus goCoderStatus) {
switch (state) {
case WZState.IDLE:
WZLog.info(TAG, "Streaming is not active");
break;
case WZState.STARTING:
WZLog.info(TAG, "Broadcast initialization");
break;
case WZState.READY:
WZLog.info(TAG, "Ready to begin streaming");
break;
case WZState.RUNNING:
WZLog.info(TAG, "Streaming is active");
break;
case WZState.STOPPING:
WZLog.info(TAG, "Broadcast shutdown");
break;
}
}
// If an error is reported by the GoCoder SDK, display a toast message containing the error details
@Override
public void onError(final WZStatus goCoderStatus) {
// Run this on the U/I thread
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.setText("Live Streaming Error: " + goCoderStatus.getLastError().getErrorDescription(), LENGTH_LONG).show();
}
});
}
}
// Begin streaming
this.goCoder.startStreaming(statusCallback);