android - 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
解决方案
推荐阅读
- node.js - 在连接池缓存中找不到 poolAlias “default”(将 Express 服务器连接到 Oracle 数据库)
- python - 如何用python建立人口金字塔
- javascript - 谷歌图表不允许我在行创建中使用变量
- java - JPA 不按 LocalDate 和 LocalTime 对记录进行排序
- terraform - 地形。helm_release 资源未显示在“helm ls”输出中
- apache-kafka - Kafka Producer/Consumer 无法连接到服务器上的 localhost kafka 集群
- php - PHP FREETDS MSSQL 和语言环境特殊字符
- vba - 将表格中的所有行提取为文本
- php - 控制器未发布,错误缺少必需的参数:id
- ggplot2 - 哪个 transition_* 用于使用 gganimate 为地图制作动画?