mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
fixed subs in player not appearing
This commit is contained in:
parent
e17428b4ed
commit
d689d5050d
2 changed files with 43 additions and 6 deletions
|
@ -2,6 +2,7 @@ package com.lagradost.cloudstream3.ui.player
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
@ -35,7 +36,7 @@ const val TAG = "CS3ExoPlayer"
|
||||||
|
|
||||||
/** Cache */
|
/** Cache */
|
||||||
|
|
||||||
class CS3IPlayer() : IPlayer {
|
class CS3IPlayer : IPlayer {
|
||||||
private var isPlaying = false
|
private var isPlaying = false
|
||||||
private var exoPlayer: ExoPlayer? = null
|
private var exoPlayer: ExoPlayer? = null
|
||||||
var cacheSize = 300L * 1024L * 1024L // 300 mb
|
var cacheSize = 300L * 1024L * 1024L // 300 mb
|
||||||
|
@ -112,6 +113,24 @@ class CS3IPlayer() : IPlayer {
|
||||||
this.prevEpisode = prevEpisode
|
this.prevEpisode = prevEpisode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// I know, this is not a perfect solution, however it works for fixing subs
|
||||||
|
private fun reloadSubs() {
|
||||||
|
exoPlayer?.applicationLooper?.let {
|
||||||
|
try {
|
||||||
|
Handler(it).post {
|
||||||
|
try {
|
||||||
|
seekTime(1L)
|
||||||
|
} catch (e : Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun initSubtitles(subView: SubtitleView?, subHolder: FrameLayout?, style: SaveCaptionStyle?) {
|
fun initSubtitles(subView: SubtitleView?, subHolder: FrameLayout?, style: SaveCaptionStyle?) {
|
||||||
subtitleHelper.initSubtitles(subView, subHolder, style)
|
subtitleHelper.initSubtitles(subView, subHolder, style)
|
||||||
}
|
}
|
||||||
|
@ -178,6 +197,13 @@ class CS3IPlayer() : IPlayer {
|
||||||
trackSelector.buildUponParameters()
|
trackSelector.buildUponParameters()
|
||||||
.setPreferredTextLanguage("_$name")
|
.setPreferredTextLanguage("_$name")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ugliest code I have written, it seeks 1ms to *update* the subtitles
|
||||||
|
//exoPlayer?.applicationLooper?.let {
|
||||||
|
// Handler(it).postDelayed({
|
||||||
|
// seekTime(1L)
|
||||||
|
// }, 1)
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
SubtitleStatus.NOT_FOUND -> {
|
SubtitleStatus.NOT_FOUND -> {
|
||||||
// not found
|
// not found
|
||||||
|
@ -261,6 +287,8 @@ class CS3IPlayer() : IPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
var requestSubtitleUpdate : (() -> Unit)? = null
|
||||||
|
|
||||||
private fun createOnlineSource(link: ExtractorLink): DataSource.Factory {
|
private fun createOnlineSource(link: ExtractorLink): DataSource.Factory {
|
||||||
// Because Trailers.to seems to fail with http/1.1 the normal one uses.
|
// Because Trailers.to seems to fail with http/1.1 the normal one uses.
|
||||||
return DefaultHttpDataSource.Factory().apply {
|
return DefaultHttpDataSource.Factory().apply {
|
||||||
|
@ -368,6 +396,8 @@ class CS3IPlayer() : IPlayer {
|
||||||
return trackSelector
|
return trackSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentTextRenderer: TextRenderer? = null
|
||||||
|
|
||||||
private fun buildExoPlayer(
|
private fun buildExoPlayer(
|
||||||
context: Context,
|
context: Context,
|
||||||
mediaItem: MediaItem,
|
mediaItem: MediaItem,
|
||||||
|
@ -389,11 +419,14 @@ class CS3IPlayer() : IPlayer {
|
||||||
textRendererOutput,
|
textRendererOutput,
|
||||||
metadataRendererOutput
|
metadataRendererOutput
|
||||||
).map {
|
).map {
|
||||||
if (it is TextRenderer) TextRenderer(
|
if (it is TextRenderer) {
|
||||||
textRendererOutput,
|
currentTextRenderer = TextRenderer(
|
||||||
eventHandler.looper,
|
textRendererOutput,
|
||||||
CustomSubtitleDecoderFactory()
|
eventHandler.looper,
|
||||||
) else it
|
CustomSubtitleDecoderFactory()
|
||||||
|
)
|
||||||
|
currentTextRenderer!!
|
||||||
|
} else it
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
}
|
}
|
||||||
.setTrackSelector(trackSelector ?: getTrackSelector(context))
|
.setTrackSelector(trackSelector ?: getTrackSelector(context))
|
||||||
|
@ -505,6 +538,8 @@ class CS3IPlayer() : IPlayer {
|
||||||
cacheFactory = cacheFactory
|
cacheFactory = cacheFactory
|
||||||
)
|
)
|
||||||
|
|
||||||
|
requestSubtitleUpdate = ::reloadSubs
|
||||||
|
|
||||||
playerUpdated?.invoke(exoPlayer)
|
playerUpdated?.invoke(exoPlayer)
|
||||||
exoPlayer?.prepare()
|
exoPlayer?.prepare()
|
||||||
|
|
||||||
|
@ -572,6 +607,7 @@ class CS3IPlayer() : IPlayer {
|
||||||
|
|
||||||
override fun onRenderedFirstFrame() {
|
override fun onRenderedFirstFrame() {
|
||||||
updatedTime()
|
updatedTime()
|
||||||
|
|
||||||
if (!hasUsedFirstRender) { // this insures that we only call this once per player load
|
if (!hasUsedFirstRender) { // this insures that we only call this once per player load
|
||||||
Log.i(TAG, "Rendered first frame")
|
Log.i(TAG, "Rendered first frame")
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,7 @@ class CustomDecoder : SubtitleDecoder {
|
||||||
}
|
}
|
||||||
decoder.queueInputBuffer(buff)
|
decoder.queueInputBuffer(buff)
|
||||||
}
|
}
|
||||||
|
CS3IPlayer.requestSubtitleUpdate?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue