Android SDK (Core)
DRM Credentials Handling in the SDK
8 min
when the sdk detects that a stream is drm protected , it will automatically trigger a request on the drmcredentials sharedflow your integration should listen for these requests, fetch the correct license, and inject it back into the sdk if the stream is not drm protected , this flow will never be triggered how it works stream starts playing if the event metadata indicates drm protection , the sdk automatically emits an nwdrmcredentialsrequest into the drmcredentials sharedflow your code collects that request, fetches the license from your preferred source, and returns it to the sdk using the request's deferred the sdk uses the returned credentials to complete playback 💡 automatic triggering if a stream is drm protected, you don’t need to call anything manually — the sdk will emit an nwdrmcredentialsrequest for you to handle request model data class nwdrmcredentialsrequest( val drmproviderid string?, // drm provider to match val drmkeyids list\<string>?, // drm key ids to match val deferred completabledeferred\<nwdrmcredentials> // return result here ) response model data class nwdrmcredentials( val keyid string?, // matched license key id val licenseurl string? // widevine license url ) example expplayback? drmcredentials? collect { req > // fetch license info (optional — use your backend, cache, etc ) val resp = viewmodel fetchdrmlicenseinfobyshowcasesid(collectionid, showcaseid) // convert requested key ids to a set for matching val keyidsset = req drmkeyids? toset() // match provider id and key ids (critical for correct license) val match = resp? keys? firstornull { (req drmproviderid == null || it drmproviderid == req drmproviderid) && (keyidsset isnullorempty() || (it keyid != null && it keyid in keyidsset)) } // find matching license info val licenseinfo = resp? licenseinfo ? firstornull { it id == match? licenseid } // build drm credentials val nwdrmcredentials = nwdrmcredentials( keyid = licenseinfo? id, licenseurl = licenseinfo? data? widevine? licenseurl ) // important complete the request so the sdk can proceed req deferred complete(nwdrmcredentials) } ⚠️ match matters always filter licenses using both drmproviderid and drmkeyids if these don’t match correctly, the wrong license may be injected, causing playback to fail drm credentials flow diagra 🚨 do not skip completion if you don’t call req deferred complete(nwdrmcredentials) — even with null values — the drm playback will not start and may lead to a no video available state conclusion when the sdk plays a drm protected stream, it automatically requests drm credentials via the drmcredentials sharedflow your responsibility is to listen for the request fetch the correct license ensure it matches drmproviderid and drmkeyids complete the request using req deferred complete(nwdrmcredentials) following this flow guarantees the right license is injected, ensuring smooth playback if matching or completion is skipped, drm playback will fail