minor fix

This commit is contained in:
LagradOst 2022-01-12 18:32:03 +01:00
parent 3f1e398ae8
commit 48c786a5b8
3 changed files with 51 additions and 30 deletions

View file

@ -11,6 +11,7 @@ import com.google.android.exoplayer2.extractor.ExtractorsFactory
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
import com.google.android.exoplayer2.source.MergingMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.text.SubtitleDecoderFactory
import com.google.android.exoplayer2.text.SubtitleExtractor
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.trackselection.TrackSelector
@ -598,11 +599,26 @@ class CS3IPlayer : IPlayer {
.setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
.build()
val ownFactory = CustomSubtitleDecoderFactory()
val extractorFactory = ExtractorsFactory {
arrayOf(
if (ownFactory.supportsFormat(format)) {
SubtitleExtractor(
CustomSubtitleDecoderFactory().createDecoder(format), format
ownFactory.createDecoder(format), format
)
} else {
if (SubtitleDecoderFactory.DEFAULT.supportsFormat(format)) {
SubtitleExtractor(
SubtitleDecoderFactory.DEFAULT.createDecoder(format), format
)
} else {
// ye we guess if not found instead of using UnknownSubtitlesExtractor,
// this way you can hopefully load a .txt file that is an srt and it will work
SubtitleExtractor(
ownFactory.createDecoder(format), format
)
}
}
)
}

View file

@ -11,6 +11,7 @@ import com.google.android.exoplayer2.text.subrip.SubripDecoder
import com.google.android.exoplayer2.text.ttml.TtmlDecoder
import com.google.android.exoplayer2.text.webvtt.WebvttDecoder
import com.google.android.exoplayer2.util.MimeTypes
import com.lagradost.cloudstream3.mvvm.logError
class CustomDecoder : SubtitleDecoder {
@ -18,7 +19,7 @@ class CustomDecoder : SubtitleDecoder {
private const val TAG = "CustomDecoder"
}
var realDecoder: SubtitleDecoder? = null
private var realDecoder: SubtitleDecoder? = null
override fun getName(): String {
return realDecoder?.name ?: this::class.java.name
@ -31,9 +32,10 @@ class CustomDecoder : SubtitleDecoder {
override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) {
Log.i(TAG, "queueInputBuffer")
try {
if (realDecoder == null) {
inputBuffer.data?.let { data ->
// this way we read the subtitle file and decide what decoder to use instead of relying on mimetype
val pos = data.position()
data.position(0)
@ -62,6 +64,9 @@ class CustomDecoder : SubtitleDecoder {
} else {
realDecoder?.dequeueInputBuffer()
}
} catch (e: Exception) {
logError(e)
}
}
override fun dequeueOutputBuffer(): SubtitleOutputBuffer? {

View file

@ -103,9 +103,9 @@ class GeneratorPlayer : FullScreenPlayer() {
val (linkData, _) = it
var quality = linkData?.quality ?: Qualities.Unknown.value
// we set all qualities above current max as max -1
// we set all qualities above current max as reverse
if (useQualitySettings && quality > currentPrefQuality) {
quality = currentPrefQuality - 1
quality = currentPrefQuality - quality - 1
}
// negative because we want to sort highest quality first
-(quality)