mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 15:32:01 +00:00
fix: libass positioning
This commit is contained in:
parent
a37c962b98
commit
74b25e5a54
1 changed files with 11 additions and 8 deletions
|
|
@ -46,7 +46,6 @@ import androidx.media3.ui.PlayerView
|
||||||
import androidx.media3.ui.SubtitleView
|
import androidx.media3.ui.SubtitleView
|
||||||
import androidx.media3.ui.CaptionStyleCompat
|
import androidx.media3.ui.CaptionStyleCompat
|
||||||
import com.nuvio.app.R
|
import com.nuvio.app.R
|
||||||
import io.github.peerless2012.ass.media.kt.withAssSupport
|
|
||||||
import io.github.peerless2012.ass.media.widget.AssSubtitleView
|
import io.github.peerless2012.ass.media.widget.AssSubtitleView
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
@ -480,14 +479,14 @@ private fun PlayerView.syncLibassOverlay(
|
||||||
enabled: Boolean,
|
enabled: Boolean,
|
||||||
renderType: LibassRenderType,
|
renderType: LibassRenderType,
|
||||||
) {
|
) {
|
||||||
val subtitleView = subtitleView ?: return
|
val overlayContainer = findViewById<android.widget.FrameLayout>(R.id.libass_overlay_container) ?: return
|
||||||
val needsOverlay = enabled && renderType.usesOverlaySubtitleView()
|
val needsOverlay = enabled && renderType.usesOverlaySubtitleView()
|
||||||
val boundPlayer = getTag(R.id.libass_overlay_bound_player) as? ExoPlayer
|
val boundPlayer = getTag(R.id.libass_overlay_bound_player) as? ExoPlayer
|
||||||
val hasOverlayChild = subtitleView.hasAssOverlayChild()
|
val hasOverlayChild = overlayContainer.hasAssOverlayChild()
|
||||||
|
|
||||||
if (!needsOverlay) {
|
if (!needsOverlay) {
|
||||||
if (hasOverlayChild) {
|
if (hasOverlayChild) {
|
||||||
subtitleView.removeAssOverlayChildren()
|
overlayContainer.removeAssOverlayChildren()
|
||||||
}
|
}
|
||||||
if (boundPlayer != null) {
|
if (boundPlayer != null) {
|
||||||
setTag(R.id.libass_overlay_bound_player, null)
|
setTag(R.id.libass_overlay_bound_player, null)
|
||||||
|
|
@ -500,15 +499,19 @@ private fun PlayerView.syncLibassOverlay(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
subtitleView.removeAssOverlayChildren()
|
overlayContainer.removeAssOverlayChildren()
|
||||||
subtitleView.withAssSupport(assHandler)
|
val assSubtitleView = AssSubtitleView(overlayContainer.context, assHandler)
|
||||||
|
overlayContainer.addView(
|
||||||
|
assSubtitleView,
|
||||||
|
android.widget.FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
||||||
|
)
|
||||||
setTag(R.id.libass_overlay_bound_player, player)
|
setTag(R.id.libass_overlay_bound_player, player)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun LibassRenderType.usesOverlaySubtitleView(): Boolean =
|
private fun LibassRenderType.usesOverlaySubtitleView(): Boolean =
|
||||||
this == LibassRenderType.OVERLAY_CANVAS || this == LibassRenderType.OVERLAY_OPEN_GL
|
this == LibassRenderType.OVERLAY_CANVAS || this == LibassRenderType.OVERLAY_OPEN_GL
|
||||||
|
|
||||||
private fun SubtitleView.hasAssOverlayChild(): Boolean {
|
private fun android.widget.FrameLayout.hasAssOverlayChild(): Boolean {
|
||||||
for (index in 0 until childCount) {
|
for (index in 0 until childCount) {
|
||||||
if (getChildAt(index) is AssSubtitleView) {
|
if (getChildAt(index) is AssSubtitleView) {
|
||||||
return true
|
return true
|
||||||
|
|
@ -517,7 +520,7 @@ private fun SubtitleView.hasAssOverlayChild(): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SubtitleView.removeAssOverlayChildren() {
|
private fun android.widget.FrameLayout.removeAssOverlayChildren() {
|
||||||
for (index in childCount - 1 downTo 0) {
|
for (index in childCount - 1 downTo 0) {
|
||||||
if (getChildAt(index) is AssSubtitleView) {
|
if (getChildAt(index) is AssSubtitleView) {
|
||||||
removeViewAt(index)
|
removeViewAt(index)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue