I'm trying to retrieve the KEYID
value from my HLS video manifest below
#EXT-X-SESSION-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,A2234527890AAAAA7e+LqXnZSs6jyCfc1R0HRoAAABgSEA9tEdoxREFwszTCHC2rRIJI88aJmwY=",KEYID=0x0F6D11DA12344170C444C21C2DAB4482,KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",KEYFORMATVERSIONS="1"
I retrieved the HLS Manifest using the code below as recommended by the ExoPlayer website
override fun onTimelineChanged(timeline: Timeline, reason: Int) {
super.onTimelineChanged(timeline, reason)
val manifest: HlsManifest? = exoPlayer.currentManifest as HlsManifest?
}
My problem is that I am unable to find that KEYID
property within that manifest
variable.
With that said, how would I go about retrieving that property?
After further inspection of the manifest
variable using Android Studios debugger, I was able to find tags
within it. It contains a list of HLS tags and within it, is KEYID
So I looped through the tags trying to find one with KEYID
and then used ChatGPT (For fun:p) to write an expression for finding that tag.
This is probably not the best way to go about it, but posting it as an answer unless someone is able to come up with a better solution.
Thanks.
override fun onTimelineChanged(timeline: Timeline, reason: Int) {
super.onTimelineChanged(timeline, reason)
val manifest: HlsManifest? = exoPlayer.currentManifest as HlsManifest?
if (manifest != null) {
val keyIdRegex = Regex("KEYID=([^,]+)")
val tags = manifest.multivariantPlaylist.tags
val keyIdMatches = tags.mapNotNull { keyIdRegex.find(it) }
for (matchResult in keyIdMatches) {
val keyId = matchResult.groupValues[1]
println("KEYID value: $keyId")
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.