google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.74k stars 6.03k forks source link

Clear keys not working Drm Sesion #10779

Closed FranEspino closed 2 years ago

FranEspino commented 2 years ago

ExoPlayer Version

2.18.1

Devices that reproduce the issue

.

Devices that do not reproduce the issue

.

Reproducible in the demo app?

No

Reproduction steps

 public void playvideoEmbed(String Url) {
        player = new SimpleExoPlayer.Builder(this)
                .setMediaSourceFactory(new
                        DefaultMediaSourceFactory(headers()))
                .build();
        playerView.setPlayer(player);
        DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();
        String vid = "https://dce-fs-live-dazn-cdn.dazn.com/dashdrm/dazn-linear-017/stream.mpd";

        Uri videoURI = Uri.parse(vid);

        String keyString = "{\"keys\":[{\"kty\":\"oct\",\"k\":\"MGQ2NzEyYmYyYTg0ZWRjYzkzZDAwMWE5NjEzZjZmZWM\",\"kid\":\"Y2ZiNWUyYjczYmVmNGYzYzg3OGYyNWFiODZhNzQ1MWY\"}],'type':\"temporary\"}";

        MediaDrmCallback drmCallback = new LocalMediaDrmCallback(keyString.getBytes());

        MediaSource dashMediaSource = new DashMediaSource.Factory(dataSourceFactory)
                .setDrmSessionManagerProvider(mediaItem -> {
                    return new DefaultDrmSessionManager.Builder()
                            .setPlayClearSamplesWithoutKeys(true)
                            .setMultiSession(false)
                            .setKeyRequestParameters(new HashMap<String,String>())
                            .setUuidAndExoMediaDrmProvider(C.CLEARKEY_UUID, FrameworkMediaDrm.DEFAULT_PROVIDER)
                            .build(drmCallback);
                })
                .createMediaSource(MediaItem.fromUri(videoURI));

        player.setMediaSource(dashMediaSource);
        player.setPlayWhenReady(true);
        player.prepare();
        player.play();

    }

Expected result

/

Actual result

E/ExoPlayerImplInternal: Playback error
      com.google.android.exoplayer2.ExoPlaybackException: MediaCodecAudioRenderer error, index=1, format=Format(audio_128kbps, null, null, audio/mp4a-latm, mp4a.40.2, 128000, de, [-1, -1, -1.0], [2, 48000]), format_supported=YES
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:566)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:246)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: android.media.MediaCodec$CryptoException: Crypto key not available
        at android.media.MediaCodec.native_queueSecureInputBuffer(Native Method)
        at android.media.MediaCodec.queueSecureInputBuffer(MediaCodec.java:2821)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.queueSecureInputBuffer(SynchronousMediaCodecAdapter.java:149)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.java:1358)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:794)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:989)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:490)
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:246) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 

Media

/

Bug Report

icbaker commented 2 years ago

Your manifest doesn't have a ContentProtection node with the Clear Key DASH-IF UUID.

The kid value in your JSON string doesn't match the default_KID value in your manifest (converting the hex default_KID to base64 gives z7XitzvvTzyHjyWrhqdFHw).

Take a look at the example here, where the clearkey ContentProtection nodes are present in the manifest and the default_KID value matches the key ID used in the clearkey response (nrQFDeRLSAKTLifXUIPiZg): https://reference.dashif.org/dash.js/latest/samples/drm/clearkey.html

FranEspino commented 2 years ago

I need some guidance, I have only worked with mpd or m3u8 files without encryption and exoplayer plays it without problems, I have been using the following tool https://developer-tools.jwplayer.com/stream-tester Doing a test with the following url: https://dce-fs-live-dazn-cdn.dazn.com/dashdrm/dazn-linear-017/stream.mpd ClearKey Key: 0d6712bf2a84edcc93d001a9613f6fec ClearKey Key ID: cfb5e2b73bef4f3c878f25ab86a7451f Now I need to play it in android studio, where should I add ContentProtection?

Could you please provide me with a complete android studio example, these are the exoplayer versions I am using:

implementation 'com.google.android.exoplayer:exoplayer-core:2.18.1'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.18.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.1'
implementation 'com.google.android.exoplayer:exoplayer-hls:2.18.1'
implementation 'com.google.android.exoplayer:extension-okhttp:2.18.1'
implementation 'com.google.android.exoplayer:extension-mediasession:2.18.1'
icbaker commented 2 years ago

It looks like you've converted 0d6712bf2a84edcc93d001a9613f6fec and cfb5e2b73bef4f3c878f25ab86a7451f into base64 by interpreting them as ASCII strings, not hex strings (maybe using a converter like https://www.base64encode.org/). I suspect this isn't correct, and that they should be considered to be hex strings.

Try a converter that will interpret the input as a hex string, e.g. https://base64.guru/converter/encode/hex

And then use the output of that in your JSON response.

FranEspino commented 2 years ago

Thanks, It work!!