Merge branch 'cmp-rewrite' of https://github.com/NuvioMedia/Nuviomobile into cmp-rewrite

This commit is contained in:
tapframe 2026-04-14 19:07:22 +05:30
commit 457d95e918
3 changed files with 28 additions and 11 deletions

View file

@ -46,7 +46,6 @@ import androidx.media3.ui.PlayerView
import androidx.media3.ui.SubtitleView
import androidx.media3.ui.CaptionStyleCompat
import com.nuvio.app.R
import io.github.peerless2012.ass.media.kt.withAssSupport
import io.github.peerless2012.ass.media.widget.AssSubtitleView
import kotlinx.coroutines.delay
import kotlinx.coroutines.Dispatchers
@ -480,14 +479,19 @@ private fun PlayerView.syncLibassOverlay(
enabled: Boolean,
renderType: LibassRenderType,
) {
val subtitleView = subtitleView ?: return
val containerId = if (renderType == LibassRenderType.OVERLAY_OPEN_GL) {
R.id.libass_overlay_container_gl
} else {
R.id.libass_overlay_container
}
val overlayContainer = findViewById<android.widget.FrameLayout>(containerId) ?: return
val needsOverlay = enabled && renderType.usesOverlaySubtitleView()
val boundPlayer = getTag(R.id.libass_overlay_bound_player) as? ExoPlayer
val hasOverlayChild = subtitleView.hasAssOverlayChild()
val hasOverlayChild = overlayContainer.hasAssOverlayChild()
if (!needsOverlay) {
if (hasOverlayChild) {
subtitleView.removeAssOverlayChildren()
overlayContainer.removeAssOverlayChildren()
}
if (boundPlayer != null) {
setTag(R.id.libass_overlay_bound_player, null)
@ -500,15 +504,19 @@ private fun PlayerView.syncLibassOverlay(
return
}
subtitleView.removeAssOverlayChildren()
subtitleView.withAssSupport(assHandler)
overlayContainer.removeAssOverlayChildren()
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)
}
private fun LibassRenderType.usesOverlaySubtitleView(): Boolean =
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) {
if (getChildAt(index) is AssSubtitleView) {
return true
@ -517,7 +525,7 @@ private fun SubtitleView.hasAssOverlayChild(): Boolean {
return false
}
private fun SubtitleView.removeAssOverlayChildren() {
private fun android.widget.FrameLayout.removeAssOverlayChildren() {
for (index in childCount - 1 downTo 0) {
if (getChildAt(index) is AssSubtitleView) {
removeViewAt(index)

View file

@ -19,10 +19,18 @@
android:layout_height="match_parent"
android:scaleType="fitXY" />
<FrameLayout
android:id="@+id/libass_overlay_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.media3.ui.AspectRatioFrameLayout>
<!-- SubtitleView is OUTSIDE the AspectRatioFrameLayout so it spans the
full player area and does not shift when the resize-mode changes. -->
<FrameLayout
android:id="@+id/libass_overlay_container_gl"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<androidx.media3.ui.SubtitleView
android:id="@id/exo_subtitles"
android:layout_width="match_parent"

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="libass_overlay_bound_player" type="id" />
</resources>
<item name="libass_overlay_container_gl" type="id" />
</resources>