mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Add setting for subtitle outline size (#375)
Adds a settings allowing for adjusting the thickness of unstyled subtitle outlines, if outline is enabled. This is applied for both ExoPlayer & MPV Closes #179  Dev note: the ExoPlayer implementation is bad code, don't write code like this. It works though
This commit is contained in:
parent
a197f6911b
commit
ac10517028
9 changed files with 116 additions and 0 deletions
|
|
@ -0,0 +1,56 @@
|
|||
package com.github.damontecres.wholphin.util
|
||||
|
||||
import androidx.media3.ui.SubtitleView
|
||||
import timber.log.Timber
|
||||
import java.lang.reflect.Field
|
||||
|
||||
/**
|
||||
* Utility class to override private fields in media3's [SubtitleView]
|
||||
*/
|
||||
class Media3SubtitleOverride(
|
||||
val outlineThicknessPx: Float,
|
||||
) {
|
||||
companion object {
|
||||
private lateinit var outputField: Field
|
||||
private lateinit var classCanvasSubtitleOutput: Class<*>
|
||||
private lateinit var paintersField: Field
|
||||
private lateinit var classSubtitlePainter: Class<*>
|
||||
private lateinit var outlineWidthField: Field
|
||||
|
||||
var initialized: Boolean
|
||||
private set
|
||||
|
||||
init {
|
||||
try {
|
||||
// This is bad times
|
||||
outputField = SubtitleView::class.java.getDeclaredField("output")
|
||||
classCanvasSubtitleOutput = Class.forName("androidx.media3.ui.CanvasSubtitleOutput")
|
||||
paintersField = classCanvasSubtitleOutput.getDeclaredField("painters")
|
||||
classSubtitlePainter = Class.forName("androidx.media3.ui.SubtitlePainter")
|
||||
outlineWidthField = classSubtitlePainter.getDeclaredField("outlineWidth")
|
||||
outputField.isAccessible = true
|
||||
outlineWidthField.isAccessible = true
|
||||
paintersField.isAccessible = true
|
||||
initialized = true
|
||||
} catch (ex: Exception) {
|
||||
Timber.w(ex, "Error initializing")
|
||||
initialized = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun apply(subtitleView: SubtitleView) {
|
||||
try {
|
||||
if (initialized) {
|
||||
// Basically hijack the field that controls the subtitle outline size
|
||||
val canvasSubtitleOutput = outputField.get(subtitleView)
|
||||
val painters = paintersField.get(canvasSubtitleOutput) as List<*>
|
||||
painters.forEach { painter ->
|
||||
outlineWidthField.set(painter, outlineThicknessPx)
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
Timber.w(ex, "Failed to apply")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue