首页 > 解决方案 > Enable DRM with JW stream

问题描述

Hello I am developing an application to play dash stream with Enable DRM with JW stream. I have read the documentation and written code accordingly. Documentation link is https://developer.jwplayer.com/jwplayer/docs/android-enable-drm-with-jw-stream

When I am trying to play the video, JW Player is showing Error code : 303200.

My sample code is :

Activity:

class MainActivity : AppCompatActivity(), OnFullscreenListener {

private var mJwPlayerView: JWPlayerView? = null
private var mCastContext: CastContext? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    mJwPlayerView = findViewById(R.id.x_jw_player_view)
    mJwPlayerView?.addOnFullscreenListener(this)
    KeepScreenOnHandler(mJwPlayerView, window)

    val pi = PlaylistItem.Builder()
        .title("Physics")
        .file("https://content.jwplatform.com/v2/media/eSj8wAMp/manifest.mpd?policy_id=VBvWkLqX&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTg4MTE5NDQsInJlc291cmNlIjoiL3YyL21lZGlhL2VTajh3QU1wL21hbmlmZXN0Lm1wZD9wb2xpY3lfaWQ9VkJ2V2tMcVgifQ.BTuEdvvct4XJehOUfGdIaj_ZToOfgfbKh2cIF0u075U")
        .mediaDrmCallback(WideVineMediaDrmCallback("https://content.jwplatform.com/v2/media/eSj8wAMp/license?drm=widevine&policy_id=VBvWkLqX&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTg4MTE5NDQsInJlc291cmNlIjoiL3YyL21lZGlhL2VTajh3QU1wL2xpY2Vuc2U_ZHJtPXdpZGV2aW5lJnBvbGljeV9pZD1WQnZXa0xxWCJ9.YHRlStSK8V1kO9XOKEqSrMFa6Ovi_aBgilxwhkd3Glo"))
        .build()

    val playListItem: ArrayList<PlaylistItem> = ArrayList()
    playListItem.add(pi)

    val playerConfig = PlayerConfig.Builder()
        .playlist(playListItem)
        .build()

    mJwPlayerView?.setup(playerConfig)

    //mCastContext = CastContext.getSharedInstance(this)

}

override fun onStart() {
    super.onStart()
    mJwPlayerView?.onStart()
}

override fun onResume() {
    super.onResume()
    mJwPlayerView?.onResume()
}

override fun onPause() {
    super.onPause()
    mJwPlayerView?.onPause()
}

override fun onStop() {
    super.onStop()
    mJwPlayerView?.onStop()
}

override fun onDestroy() {
    super.onDestroy()
    mJwPlayerView?.onDestroy()
}


override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (mJwPlayerView?.fullscreen == true) {
            mJwPlayerView?.setFullscreen(false, true)
            return false
        }
    }
    return super.onKeyDown(keyCode, event)
}

override fun onFullscreen(fullscreenEvent: FullscreenEvent?) {
    val actionBar = supportActionBar
    if (actionBar != null) {
        if (fullscreenEvent?.fullscreen == true) {
            actionBar.hide()
        } else {
            actionBar.show()
        }
    }
}

}

DRM Callback :

class WideVineMediaDrmCallback(private val wideVineUrl: String?) : MediaDrmCallback {

private var defaultUri: String? = null

init {
    defaultUri = wideVineUrl
}

override fun executeProvisionRequest(p0: UUID?, p1: ExoMediaDrm.ProvisionRequest?): ByteArray {
    val url = p1?.defaultUrl + "&signedRequest=" + p1?.data.toString()
    return executePost(url, null, null)
}

override fun executeKeyRequest(p0: UUID?, p1: ExoMediaDrm.KeyRequest?): ByteArray {
    var url = p1?.licenseServerUrl
    if (TextUtils.isEmpty(url)) {
        url = defaultUri
    }
    return executePost(url, null, null)
}

@Throws(IOException::class)
fun executePost(
    url: String?,
    data: ByteArray?,
    requestProperties: Map<String?, String?>?
): ByteArray {
    var urlConnection: HttpURLConnection? = null
    return try {
        urlConnection = URL(url).openConnection() as HttpURLConnection
        urlConnection.requestMethod = "POST"
        urlConnection.doOutput = data != null
        urlConnection.doInput = true
        if (requestProperties != null) {
            for ((key, value) in requestProperties) {
                urlConnection.setRequestProperty(key, value)
            }
        }
        // Write the request body, if there is one.
        if (data != null) {
            val out: OutputStream = urlConnection.outputStream
            try {
                out.write(data)
            } finally {
                out.close()
            }
        }
        // Read and return the response body.
        val inputStream: InputStream = urlConnection.inputStream
        try {
            Util.toByteArray(inputStream)
        } finally {
            inputStream.close()
        }
    } finally {
        urlConnection?.disconnect()
    }
}

}

My complete demo project link is : https://github.com/vikashbhr/enable_drm_with_jw_stream

标签: androidjwplayer

解决方案


推荐阅读