How to live stream with Wowza GoCoder SDK for Android

This article describes how to start, stop, and monitor a live stream broadcast with Wowza GoCoder™ SDK for Android.

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 (!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);
  }
}

Stop streaming


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

if (this.goCoder.isStreaming()) {
  // Stop the live stream
  this.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
WZState.IDLE The stream is inactive. This is the status before and after the broadcast.
WZState.STARTING The audio and video inputs are initializing and the stream is connecting to a Wowza Streaming Engine server or the Wowza Streaming Cloud service.
WZState.READY The audio, video, and stream connection are successfully initialized.
WZState.RUNNING The broadcast is actively streaming.
WZState.STOPPING The streaming connection is closing. After the connection closes, the broadcast status returns to WZState.IDLE.

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

//
// 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);

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