Mux Player for Android | Mux

Mux Player for Android

The Mux Player SDK for Android extends media3 to play Mux video in native Android apps. Use this guide to install the SDK, play an asset, and secure playback.

In this guide:

  1. Install the Mux Player SDK
    Add the SDK to your project and app
  2. Play a Mux Asset
    Play an asset from Mux Video in a native Android app
  3. Control Your Usage and Quality
    Build for your specific bandwidth, cost, and quality needs using playback parameters
  4. Add or customize Mux Data metadata
    Enrich your included Mux Data integration with additional metadata
  5. Secure your playback experience
    Play Mux Video content securely using the option that works best for you and your users
  6. Download Mux Assets for offline playback
    Use Mux Player to download and store Mux Video content, including DRM-protected content, for offline playback
  7. Advanced Features
    Advanced customization and features for the Mux Player SDK

The Mux Player SDK is a thin wrapper on top of Google's media3 player SDK with convenient tools for Mux Video users. This SDK is not required to use Mux Video, but it can help you do things like controlling your data and delivery usage, playing Mux assets by ID, automatically supporting player features like caching, and transparently tracking performance and engagement with Mux Data.

1. Install the Mux Player SDK

Add our repository to your Gradle project

Add Mux's maven repository to your gradle files. Newer projects require declaring this in settings.gradle, and older projects require it to be set in the project-level build.gradle.

// Add the repository here

Add the dependency to your app

Add our library to the dependencies block for your app.

implementation 'com.mux.stats.sdk:mux-stats-sdk-android:VERSION'

2. Play a Mux Asset

Create a MuxPlayer

To use the SDK, you must create a MuxPlayer object using its Builder. The basic configuration will enable all of Mux Video's features, and you can make additional config changes using our Builder. Almost all of our default config options are the same as ExoPlayer's.

MuxPlayer muxPlayer = new MuxPlayer.Builder(context).build();

Play a Mux Video asset

To play a Mux Video asset using this SDK, you can use our MediaItems API to create new instances of media3's MediaItem or MediaItem.Builder.

MediaItem mediaItem = MediaItems.fromMuxPlaybackId("playback_id");
muxPlayer.setMediaItem(mediaItem);
muxPlayer.prepare();
muxPlayer.play();

Protecting your content

Mux Video offers options for securing your content from unauthorized playing or recording.

Control Your Usage and Quality

Enable smart caching to improve experience and decrease usage

Mux Player can cache content as it is requested from Mux Video and store it for later requests.

muxPlayer.enableCaching();

Limit data and delivery usage

You may need to control your Mux Video usage or your app's data bandwidth usage.

PlaybackResolution resolution = new PlaybackResolution(720);
MediaItem mediaItem = MediaItems.fromMuxPlaybackId("playback_id").setPlaybackResolution(resolution);

Guarantee a minimum resolution

Some use cases require a minimum playback resolution.

mediaItem.setMinimumResolution(480);

Add or customize Mux Data metadata

The Mux Player SDK integrates with Mux Data to monitor for issues and track engagement with your content. You can customize this information via the CustomerData class.

CustomerData customerData = new CustomerData();
customerData.setUserId("user_id");

Secure your playback experience

Depending on your needs, you may need to secure your videos against unauthorized copying or viewing.

Signed Playback URLs

Mux Player supports playing Mux Video assets with signed playback. You can supply your JWT to MediaItems.fromMuxPlaybackId.

MediaItem signedMediaItem = MediaItems.fromMuxPlaybackId("playback_id", "jwt_token");

Digital Rights Management (DRM)

Mux Player can be configured to protect videos from unauthorized use via Widevine DRM.

Download Mux Assets for offline playback

Using MuxDownloadManager

Mux Player provides a simplified API for downloading Mux Assets for offline playback.

MuxDownloadManager downloadManager = new MuxDownloadManager();
downloadManager.startDownload(mediaItem);

Querying the download store

MuxDownloadManager provides ways to query the download store for the status of downloads.

List<DownloadStatus> downloads = downloadManager.allDownloads();

Playing downloaded Mux Assets

Playing downloaded assets is nearly the same as playing a regular Mux Asset.

MediaItem downloadedMediaItem = MediaItems.fromDownloadedMuxAsset("asset_id");
muxPlayer.setMediaItem(downloadedMediaItem);

Advanced Features

Enable smart caching

Mux Player can cache content as it is requested from Mux Video and store it for later requests.

muxPlayer.enableSmartCaching();

Use a custom Mux Video domain

If you are using a Mux Video Custom Domain, you can specify the domain on a per-MediaItem basis.

mediaItem.setCustomDomain("custom.domain.com");

Instant Clipping

Instant clipping allows you to request a stream whose start time is at some later point in the video.

mediaItem.setClipStart(30); // Start 30 seconds in
mediaItem.setClipEnd(60); // End 60 seconds in