Improve DisplayHelper.

This commit is contained in:
Isira Seneviratne 2023-06-17 06:48:11 +05:30
parent cfce1fa9f9
commit 7844467ad7
2 changed files with 5 additions and 12 deletions

View File

@ -11,12 +11,8 @@ object DisplayHelper {
* Returns false on and below SDK 24 * Returns false on and below SDK 24
*/ */
fun supportsHdr(context: Context): Boolean { fun supportsHdr(context: Context): Boolean {
val displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY) context.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { .hdrCapabilities.supportedHdrTypes.isNotEmpty()
display.hdrCapabilities.supportedHdrTypes.isNotEmpty()
} else {
false
}
} }
} }

View File

@ -59,11 +59,8 @@ object PlayerHelper {
* Create a base64 encoded DASH stream manifest * Create a base64 encoded DASH stream manifest
*/ */
fun createDashSource(streams: Streams, context: Context, audioOnly: Boolean = false): Uri { fun createDashSource(streams: Streams, context: Context, audioOnly: Boolean = false): Uri {
val manifest = DashHelper.createManifest( val supportsHdr = DisplayHelper.supportsHdr(context)
streams, val manifest = DashHelper.createManifest(streams, supportsHdr, audioOnly)
DisplayHelper.supportsHdr(context),
audioOnly
)
// encode to base64 // encode to base64
val encoded = Base64.encodeToString(manifest.toByteArray(), Base64.DEFAULT) val encoded = Base64.encodeToString(manifest.toByteArray(), Base64.DEFAULT)