Play a live stream with Wowza GoCoder SDK for Android

Learn how to add build an app with the Wowza GoCoder™ SDK for Android that can play a live stream, including an ultra low latency live stream from the Wowza Streaming Cloud™ service.

Notes:

  • Creating ultra low latency stream targets requires a separate subscription to Wowza Streaming Cloud with Ultra Low Latency.
  • Ultra low latency streams are subject to a default viewer limit of simultaneous viewers per stream according to the subscription plan you select. If this limit is exceeded, new stream viewers will receive an error and won't be able to establish a connection. If you have enabled and configured HLS as a backup for playback, ultra low latency stream viewers beyond the allotted limit can view the steam via the fallback HLS connection. See Wowza Streaming Cloud REST API limits for more information about limits.
  • Playback over SSL isn't supported by GoCoder SDK at this time.

Contents


OS and device support
Add a player view to an app
Specify the streaming server
Configure Apple HLS fallback
Set optional configurations
Play the stream
More resources

OS and device support


Playback functionality in the GoCoder SDK is supported on Android 6.0 (level 23) or later. Performance varies across devices.

Add a player view to an app


Use the WOWZPlayerView class to add a player view to an app.

  1. Create a PlayerActivity in your base activity.
  2. In your PlayerActivity layout resource file, add a WOWZPlayerView construct.
     
    <com.wowza.gocoder.sdk.api.player.WOWZPlayerView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/vwStreamPlayer"
    android:layout_alignParentStart="false"
    android:layout_centerInParent="true" />
  3. Get a reference to your resource object.
     
    mStreamPlayerView = (WOWZPlayerView) findViewById(R.id.vwStreamPlayer);

Specify the streaming server


Specify the streaming server connection properties.

  1. Use the WOWZPlayerConfig object to specify the connection properties to the streaming server.
     
    mStreamPlayerConfig = new WOWZPlayerConfig();
    mStreamPlayerConfig.setIsPlayback(true);
    mStreamPlayerConfig.setHostAddress("your-server-ip");
    mStreamPlayerConfig.setApplicationName("live");
    mStreamPlayerConfig.setStreamName("myStream");
    mStreamPlayerConfig.setPortNumber(1935);
  2. Pass the WOWZPlayerConfig object with the server information and a callback status object to the WOWZPlayerView class.
     
    class StatusCallback implements WOWZStatusCallback{
    @Override
    public void onWZStatus(WOWZStatus wzStatus) {
    }
    @Override
    public void onWZError(WOWZStatus wzStatus) {
    }
    }

Configure Apple HLS fallback


You can instruct the Wowza GoCoder SDK app to play an Apple HLS stream as a fallback if the primary stream fails to connect.

Note: If you're receiving an ultra low latency stream from the Wowza Streaming Cloud REST API, the target must be configured to enable HLS fallback. For instructions, see the Get started with ultra low latency streaming using the Wowza Streaming Cloud REST API. HLS fallback helps ensure successful playback but increases latency.

Property Type Description
setHLSEnabled Boolean Set to true to force the player to use Apple HLS instead of the default playback protocol.
setHLSBackupURL string The .m3u8 playlist URL to use as a fallback.

When specified, the player will switch to the Apple HLS URL after three failed attempts to play over the primary protocol. 

mStreamPlayerConfig.setHLSEnabled(true);
mStreamPlayerConfig.setHLSBackupURL("http://[wowza-server-ip]:1935/[application]/[streamName]/playlist.m3u8");

Set optional configurations


  • To enable or disable audio for the stream, use the setAudioEnabled method in the WOWZPlayerConfig class. To enable or disable video, use the setVideoEnabled method in the WOWZPlayerConfig class.

    To enable:

    mStreamPlayerConfig.setAudioEnabled(true);
    mStreamPlayerConfig.setVideoEnabled(true);

    To disable:

    mStreamPlayerConfig.setAudioEnabled(false);
    mStreamPlayerConfig.setVideoEnabled(false);
  • To control the volume, use the setVolume method in the WOWZPlayerView class:
     
    mStreamPlayerView.setVolume(3);
  • To configure the scale mode, use the setScaleMode method of the WOWZPlayerView class:
     
    // WOWZMediaConfig.FILL_VIEW : WOWZMediaConfig.RESIZE_TO_ASPECT;
    mStreamPlayerView.setScaleMode(WOWZMediaConfig.FILL_VIEW);

Play the stream


Use the play() method in the WOWZPlayerView class to play the live stream from the specified server.

WOWZStatusCallback statusCallback = new StatusCallback();
mStreamPlayerView.play(mStreamPlayerConfig, statusCallback);

More resources