Day 3 · 15 min read

Android Media Players

ExoPlayer, third-party players, integration patterns.

The shortlist of players

In practice on Android you have three realistic options:

ExoPlayer / Media3 essentials

ExoPlayer's DRM integration revolves around:

  • DefaultDrmSessionManager — manages session lifecycle.
  • HttpMediaDrmCallback — does the licence-server HTTP roundtrip.
  • OfflineLicenseHelper — utility for downloading + storing offline keysets.

A typical wiring:

val callback = HttpMediaDrmCallback(LICENSE_URL, dataSourceFactory).apply {
    setKeyRequestProperty("Authorization", "Bearer $appToken")
}

val drmManager = DefaultDrmSessionManager.Builder()
    .setUuidAndExoMediaDrmProvider(C.WIDEVINE_UUID, FrameworkMediaDrm.DEFAULT_PROVIDER)
    .setMultiSession(true)
    .build(callback)

Then plug it into a media source:

val source = DashMediaSource.Factory(dataSourceFactory)
    .setDrmSessionManagerProvider { drmManager }
    .createMediaSource(MediaItem.fromUri(MANIFEST_URL))

Offline with ExoPlayer

OfflineLicenseHelper handles the offline-keyset dance for you:

val helper = OfflineLicenseHelper.newWidevineInstance(
    LICENSE_URL,
    httpDataSourceFactory,
    DrmSessionEventListener.EventDispatcher()
)

val keysetId = helper.downloadLicense(
    DrmInitData(SchemeData(C.WIDEVINE_UUID, "video/mp4", initData))
)

helper.release()
saveKeysetId(contentId, keysetId)

At replay time you set the saved keyset on the session manager:

val drmManager = DefaultDrmSessionManager.Builder()
    .setUuidAndExoMediaDrmProvider(C.WIDEVINE_UUID, FrameworkMediaDrm.DEFAULT_PROVIDER)
    .build(callback)
drmManager.setMode(DefaultDrmSessionManager.MODE_PLAYBACK, savedKeysetId)

Common configuration knobs

SettingPurpose
setMultiSession(true)Required for live key rotation
setKeyRequestProperty(name, value)Add auth headers / app context to licence requests
setForceSessionsForAudioAndVideoTracksWhen audio+video have different KIDs
setUseDrmSessionsForClearPeriodsKeep DRM session alive across unencrypted ad breaks
Common pitfall

Don't fight ExoPlayer's defaults until you know what they do. The most common bug from "tuning" the DRM session manager is missing renewals.

When you'd reach for a third-party player

  • You ship to web + iOS + Android and need behaviourally-identical playback (analytics, ad insertion, watermarking).
  • You have aggressive SLA requirements.
  • You need vendor-supplied test rigs and certified device coverage.

For any other case ExoPlayer is the right choice.

No questions yet for android-players. Add some in content/questions/android-players.json.