diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt index 8cceec47..0ede20d7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt @@ -73,7 +73,7 @@ class CustomDecoder : SubtitleDecoder { private var realDecoder: SubtitleDecoder? = null override fun getName(): String { - return realDecoder?.name ?: this::class.java.name + return realDecoder?.name ?: this::javaClass.name } override fun dequeueInputBuffer(): SubtitleInputBuffer { @@ -127,6 +127,11 @@ class CustomDecoder : SubtitleDecoder { } } + private fun SubtitleInputBuffer.setSubtitleText(text: String) { +// println("Set subtitle text -----\n$text\n-----") + this.data = ByteBuffer.wrap(text.toByteArray(charset(UTF_8))) + } + override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) { Log.i(TAG, "queueInputBuffer") try { @@ -152,7 +157,7 @@ class CustomDecoder : SubtitleDecoder { ) realDecoder?.let { decoder -> decoder.dequeueInputBuffer()?.let { buff -> - if (decoder::class.java != SsaDecoder::class.java) { + if (decoder !is SsaDecoder) { if (regexSubtitlesToRemoveCaptions) captionRegex.forEach { rgx -> str = str.replace(rgx, "\n") @@ -162,8 +167,7 @@ class CustomDecoder : SubtitleDecoder { str = str.replace(rgx, "\n") } } - buff.data = ByteBuffer.wrap(str.toByteArray(charset(UTF_8))) - + buff.setSubtitleText(str) decoder.queueInputBuffer(buff) Log.i( TAG, @@ -180,7 +184,7 @@ class CustomDecoder : SubtitleDecoder { if (!inputString.isNullOrBlank()) { var str: String = inputString - if (realDecoder!!::class.java != SsaDecoder::class.java) { + if (realDecoder !is SsaDecoder) { if (regexSubtitlesToRemoveCaptions) captionRegex.forEach { rgx -> str = str.replace(rgx, "\n") @@ -190,7 +194,7 @@ class CustomDecoder : SubtitleDecoder { str = str.replace(rgx, "\n") } } - inputBuffer.data = ByteBuffer.wrap(str.toByteArray(charset(UTF_8))) + inputBuffer.setSubtitleText(str) } realDecoder?.queueInputBuffer(inputBuffer) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt index 50eb758a..f7fb3139 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt @@ -22,6 +22,8 @@ import androidx.annotation.IntDef import com.google.android.exoplayer2.* import com.google.android.exoplayer2.source.SampleStream.ReadDataResult import com.google.android.exoplayer2.text.* +import com.google.android.exoplayer2.text.Cue.DIMEN_UNSET +import com.google.android.exoplayer2.text.Cue.LINE_TYPE_NUMBER import com.google.android.exoplayer2.util.Assertions import com.google.android.exoplayer2.util.Log import com.google.android.exoplayer2.util.MimeTypes @@ -308,7 +310,18 @@ open class NonFinalTextRenderer @JvmOverloads constructor( } private fun invokeUpdateOutputInternal(cues: List) { - output.onCues(cues.map { cue -> cue.buildUpon().setSize(Cue.DIMEN_UNSET).build() }) // this fixes https://github.com/LagradOst/CloudStream-3/issues/717 + output.onCues(cues.map { cue -> + val builder = cue.buildUpon() + + // See https://github.com/google/ExoPlayer/issues/7934 + // SubripDecoder texts tend to be DIMEN_UNSET which pushes up the + // subs unlike WEBVTT which creates an inconsistency + if (cue.line == DIMEN_UNSET) + builder.setLine(-1f, LINE_TYPE_NUMBER) + + // this fixes https://github.com/LagradOst/CloudStream-3/issues/717 + builder.setSize(DIMEN_UNSET).build() + }) } /** diff --git a/app/src/main/res/layout/fragment_result_swipe.xml b/app/src/main/res/layout/fragment_result_swipe.xml index 2850687b..668e413b 100644 --- a/app/src/main/res/layout/fragment_result_swipe.xml +++ b/app/src/main/res/layout/fragment_result_swipe.xml @@ -16,7 +16,7 @@ android:orientation="horizontal" android:gravity="center_vertical" android:layout_gravity="center_vertical" - android:layout_width="wrap_content" + android:layout_width="match_parent" android:layout_height="wrap_content">