Learn how to add build an app with the Wowza GoCoder™ SDK for Android that can play 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.
- Playback over SSL isn't supported by GoCoder SDK at this time.
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.
OS and device support
Playback functionality in the GoCoder SDK is supported on Android 6.0 (level 23) or later. Performance varies across devices.
Set up an ultra low latency stream target in Wowza Streaming Cloud
For Wowza Gocoder playback from the Wowza Streaming Cloud with ultra low latency service, start by setting up an ultra low latency stream target. For instructions, see one of these resources:
- Get started with ultra low latency streaming using the Wowza Streaming Cloud REST API
- Add an ultra low latency stream target
Note: If you want to configure the ultra low latency target to enable HLS fallback, you must do so while creating the target. HLS fallback helps ensure successful playback but increases latency.
After you set up the stream target, note the WOWZ Playback URL and the optional HLS fallback URL, as you will use them to set up the WOWZPlayerConfig object.
Add a player view to an app
Use the WOWZPlayerView class to add a player view to an app.
- Create a PlayerActivity in your base activity.
- 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" />
- Get a reference to your resource object.
mStreamPlayerView = (WOWZPlayerView) findViewById(R.id.vwStreamPlayer);
Specify the streaming server
Specify the streaming server connection properties for playback.
- Use the WOWZPlayerConfig object to specify the connection properties to the streaming server.
mStreamPlayerConfig = new WOWZPlayerConfig(); mStreamPlayerConfig.setIsPlayback(true); mStreamPlayerConfig.setHostAddress("your-host"); mStreamPlayerConfig.setApplicationName("your-application-name"); mStreamPlayerConfig.setStreamName("your-stream-name"); mStreamPlayerConfig.setPortNumber(1935);
Parse the ultra low latency WOWZ playback URL to get the necessary values. For example, using this WOWZ playback URL,
wowz://edge.cdn.wowza.com/live/_definst_/0ABC2R1FvREJWak43cmxBOGhQTH12345
The configuration should look something like this:mStreamPlayerConfig = new WOWZPlayerConfig(); mStreamPlayerConfig.setIsPlayback(true); mStreamPlayerConfig.setHostAddress("edge.cdn.wowza.com"); mStreamPlayerConfig.setApplicationName("live"); mStreamPlayerConfig.setStreamName("0ABC2R1FvREJWak43cmxBOGhQTH12345"); mStreamPlayerConfig.setPortNumber(1935);
- 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
If you've enabled HLS fallback for your ultra low latency stream, you can instruct the Wowza GoCoder SDK app to play an HLS stream as a fallback if the primary WOWZ over WebSocket stream fails to connect. The player will switch to the HLS URL after three failed attempts to play over the primary WOWZ over WebSocket protocol.
HLS fallback also helps with viewer limits. 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.
Use the following properties in WowzaPlayerConfig to set up HLS fallback
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. |
Update the WOWZPlayerConfig object to add the following:
mStreamPlayerConfig.setHLSEnabled(true); mStreamPlayerConfig.setHLSBackupURL("https://[wowza-subdomain]/hls/live/833664/0ABC2R1FvREJWak43cmxBOGhQTH12345/playlist.m3u8");
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, this);
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);