LibreTube/app/src/main/java/com/github/libretube/util/PlayerHelper.kt

37 lines
1.2 KiB
Kotlin
Raw Normal View History

2022-07-17 01:01:15 +05:30
package com.github.libretube.util
import android.content.Context
import android.view.accessibility.CaptioningManager
import com.github.libretube.obj.PipedStream
import com.google.android.exoplayer2.ui.CaptionStyleCompat
object PlayerHelper {
2022-07-17 02:19:32 +05:30
private val TAG = "PlayerHelper"
2022-07-17 01:01:15 +05:30
// get the best bit rate from audio streams
fun getMostBitRate(audios: List<PipedStream>): String {
var bitrate = 0
2022-07-17 02:19:32 +05:30
var audioUrl = ""
audios.forEach {
2022-07-24 01:31:37 +05:30
if (it.bitrate != null && it.bitrate!! > bitrate) {
bitrate = it.bitrate!!
2022-07-17 02:19:32 +05:30
audioUrl = it.url.toString()
2022-07-17 01:01:15 +05:30
}
}
2022-07-17 02:19:32 +05:30
return audioUrl
2022-07-17 01:01:15 +05:30
}
// get the system default caption style
fun getCaptionStyle(context: Context): CaptionStyleCompat {
2022-07-18 23:06:21 +05:30
val captioningManager =
context.getSystemService(Context.CAPTIONING_SERVICE) as CaptioningManager
2022-07-17 01:01:15 +05:30
return if (!captioningManager.isEnabled) {
// system captions are disabled, using android default captions style
CaptionStyleCompat.DEFAULT
} else {
// system captions are enabled
CaptionStyleCompat.createFromCaptionStyle(captioningManager.userStyle)
}
}
2022-07-17 02:19:32 +05:30
}