Android Question Exoplayer and drm clearkey

Sjuanj

Member
Greetings to all

Can someone help me to pass this code from android studio to b4a?
B4X:
     playVideo("nrQFDeRLSAKTLifXUIPiZg","FmY0xnWCPCNaSpRG-tUuTQ")
	
	fun playVideo( id: String, value: String){
        try {
            drmSessionManager =
                    Util.getDrmUuid(C.CLEARKEY_UUID.toString())?.let { buildDrmSessionManager(
                            it,
                            true,
                            id,
                            value
                    ) }
        } catch (e: UnsupportedDrmException) {
            e.printStackTrace()
        }
        exoPlayer?.prepare(buildDashMediaSource(Uri.parse("https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_ClearKey.mpd")))

        exoPlayer?.playWhenReady = true

    }


    @Throws(UnsupportedDrmException::class)
    private fun buildDrmSessionManager(uuid: UUID, multiSession: Boolean, id: String, value: String): DefaultDrmSessionManager {
        val drmCallback = LocalMediaDrmCallback("{\"keys\":[{\"kty\":\"oct\",\"k\":\"${value}\",\"kid\":\"${id}\"}],\"type\":\"temporary\"}".toByteArray())
        val mediaDrm = FrameworkMediaDrm.newInstance(uuid)
        return DefaultDrmSessionManager(uuid, mediaDrm, drmCallback, null, multiSession)
    }

I know it can be done because I have seen something similar in several posts on this forum:

I've looked up and down the forum but can't find anything, and I've done 200 tests, but I can't get it to work.
It seems easy, but I can't do it.
I would be very grateful to anyone who can give me a hand.

Thank you
 

Sjuanj

Member
Hello again

I have managed to create a drmSessionManager, I have tested it and it does not give any errors, and the data it gives is similar to what it gives with android studio.
But now I don't know how to pass it to the exoplayer player.
If anyone would like to help me I would be very grateful.

B4X:
sub create_drmsession

    Dim keyString As String
    keyString = $"{\"keys\":[{\"kty\":\"oct\",\"k\":\"nrQFDeRLSAKTLifXUIPiZg\",\"kid\":\"FmY0xnWCPCNaSpRG-tUuTQ\"}],'type':\"temporary\"}"$
    
    Dim drmCallback As JavaObject
    drmCallback.InitializeNewInstance("com.google.android.exoplayer2.drm.LocalMediaDrmCallback", Array(keyString.GetBytes("UTF8")))

    Dim uuid As JavaObject
    Dim mediaDrm As JavaObject

    uuid = uuid.InitializeStatic("java.util.UUID").RunMethod("fromString", Array("e2719d58-a985-b3c9-781a-b030af78d30e"))
    mediaDrm = mediaDrm.InitializeStatic("com.google.android.exoplayer2.drm.FrameworkMediaDrm").RunMethod("newInstance", Array (uuid))
    Dim drmSessionManager As JavaObject
    drmSessionManager.InitializeNewInstance("com.google.android.exoplayer2.drm.DefaultDrmSessionManager", _
    Array(uuid, mediaDrm, drmCallback, Null, True))
    
    Return drmSessionManager

End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…