Control live streams with GoCoder SDK for Android

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

Before you begin


Before adding the functionality below to your 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 Android Studio project to use the SDK.

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

Start streaming


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

//Make sure streaming isn't already active
if (!this.goCoder.isStreaming()) {
  // Validate the current broadcast config
  WOWZStreamingError configValidationError = this.goCoder.getConfig().validateForBroadcast();
  if (configValidationError != null) {
    WOWZLog.error(configValidationError);
  } else {
    // Start the live stream
    this.goCoder.startStreaming(statusCallback);
  }
}
 
Note: If you start a broadcast and logs record a "Decreasing bitrate to..." message, 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 (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 WOWZBroadcastStatusCallback interface. This interface defines the following callbacks that are invoked for a live stream broadcast:

Status Description
BroadcastState.IDLE The stream is inactive. This is the status before and after the broadcast.
BroadcastState.READY The audio, video, and stream connection are successfully initialized.
BroadcastState.BROADCASTING The broadcast is actively streaming.

The following example shows successful status transitions and an error status:

//
// Methods implemented for the WOWZBroadcastStatusCallback interface
//

// A successful status transition has been reported by the GoCoder SDK  
WOWZBroadcastStatusCallback statusCallback = new WOWZBroadcastStatusCallback() {
  @Override
  public void onSuccess(final WOWZBroadcastStatus goCoderStatus) {
    switch (state) {
      case BroadcastState.IDLE:
        WOWZLog.info(TAG, "Streaming is not active");
        break;

      case BroadcastState.READY:
        WOWZLog.info(TAG, "Ready to begin streaming");
        break;

      case BroadcastState.BROADCASTING:
        WOWZLog.info(TAG, "Streaming is active");
        break;
    }
  }

  // If an error is reported by the GoCoder SDK, display a toast message containing the details   
  @Override
  public void onError(final WOWZBroadcastStatus 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);

More resources