Live stream with Wowza GoCoder SDK for Android

Learn 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
More resources

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 WOWZStatusCallback interface. This interface defines the following callbacks that are invoked for a live stream broadcast:

Status Description
WOWZState.IDLE The stream is inactive. This is the status before and after the broadcast.
WOWZState.STARTING The audio and video inputs are initializing and the stream is connecting to a Wowza Streaming Engine server or the Wowza Streaming Cloud live stream.
WOWZState.READY The audio, video, and stream connection are successfully initialized.
WOWZState.RUNNING The broadcast is actively streaming.
WOWZState.STOPPING The streaming connection is closing. After the connection closes, the broadcast status returns to WOWZState.IDLE.

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

//
// Methods implemented for the WOWZStatusCallback interface
//

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

      case WOWZState.STARTING:
        WOWZLog.info(TAG, "Broadcast initialization");
        break;

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

      case WOWZState.RUNNING:
        WOWZLog.info(TAG, "Streaming is active");
        break;

      case WOWZState.STOPPING:
        WOWZLog.info(TAG, "Broadcast shutdown");
        break;
    }
  }

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