androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.75k stars 421 forks source link

HOWTO: Use DRM with CastPlayer #1562

Open Soft-Buddy opened 4 months ago

Soft-Buddy commented 4 months ago

I'm using ExoPlayer and CastPlayer in my app. I managed to configure ClearKey drm for my Dash stream and got it working in ExoPlayer. I want to ask if there's any way to configure ClearKey drm for CastPlayer?

marcbaechinger commented 4 months ago

Thanks for your question. I'm not talking from experience in the sense that I'd have done this myself. The follwoing is kust about the APIs as far as I understand it from the documentation. Somereaders may be much better informaed about how the Cast SDK or devices on which cast is running support Dash with DRM.

As far as I understand from the Cast documentation there are two types of DASH streams with DRM that are supported.

The first type has all the information in the manifest and just works.

The second type need a licence URI that need to be passed from the sender (the Android app with CastPlayer) to the receivever. The receiver then needs to get the licence URI from the load request and set it accordingly with a PlaybackRequest updated accordingly. Latter is something that needs to be done on your receiver side, I can't help you with this due to lack of knowledge and experience.

As the snippet in [1] shows, you can pass the licence in any way your receiver understands. DefaultMeidItemConverter adds any DRM information that are part of the Media3 MediaItem in the JSON document that it writes to the custom data of the cast media item. You can reuse that and get the DRM info from that JSON. As an altarnative, you can write your own MediaItemConverter and pass it to the constructor of CastPlayer. There you can then convert the DRM linces into the cast item in a diffeent way if this is required.

It' important to note that your receiver needs to understand this, get the data from the load request (like from the JSON do in the custom data ) and do what's documented in [1].

I hope this helps as a starting point. There are users here that read this that have more experience with DRM on cast devices I guess. If you are lucky someone shares with you from their DASH with DRM on cast devices. Else [1] and [2] are the Cast/DASH/DRM resources I was using to respond to your question.

[1] https://developers.google.com/cast/docs/media/streaming_protocols#drm [2] https://developers.google.com/cast/docs/media/streaming_protocols#dynamic_adaptive_streaming_over_http_dash