forked from recloudstream/cloudstream
This commit is contained in:
parent
0321368128
commit
b5e97618ba
3 changed files with 48 additions and 14 deletions
|
@ -40,6 +40,7 @@ class CS3IPlayer : IPlayer {
|
|||
private var isPlaying = false
|
||||
private var exoPlayer: ExoPlayer? = null
|
||||
var cacheSize = 300L * 1024L * 1024L // 300 mb
|
||||
private var simpleCacheSize = 100L * 1024L * 1024L
|
||||
|
||||
private val seekActionTime = 30000L
|
||||
|
||||
|
@ -143,13 +144,14 @@ class CS3IPlayer : IPlayer {
|
|||
link: ExtractorLink?,
|
||||
data: ExtractorUri?,
|
||||
startPosition: Long?,
|
||||
subtitles: Set<SubtitleData>
|
||||
subtitles: Set<SubtitleData>,
|
||||
subtitle: SubtitleData?
|
||||
) {
|
||||
Log.i(TAG, "loadPlayer")
|
||||
if (sameEpisode) {
|
||||
saveData()
|
||||
} else {
|
||||
currentSubtitles = null
|
||||
currentSubtitles = subtitle
|
||||
playbackPosition = 0
|
||||
}
|
||||
|
||||
|
@ -420,6 +422,7 @@ class CS3IPlayer : IPlayer {
|
|||
playbackPosition: Long,
|
||||
playBackSpeed: Float,
|
||||
subtitleOffset: Long,
|
||||
cacheSize: Long,
|
||||
playWhenReady: Boolean = true,
|
||||
cacheFactory: CacheDataSource.Factory? = null,
|
||||
trackSelector: TrackSelector? = null,
|
||||
|
@ -446,6 +449,16 @@ class CS3IPlayer : IPlayer {
|
|||
}.toTypedArray()
|
||||
}
|
||||
.setTrackSelector(trackSelector ?: getTrackSelector(context))
|
||||
.setLoadControl(
|
||||
DefaultLoadControl.Builder()
|
||||
.setTargetBufferBytes(if (cacheSize > Int.MAX_VALUE) Int.MAX_VALUE else cacheSize.toInt())
|
||||
.setBufferDurationsMs(
|
||||
DefaultLoadControl.DEFAULT_MIN_BUFFER_MS,
|
||||
((cacheSize * 75L) / 32768L).toInt(), // 500mb = 20min
|
||||
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS,
|
||||
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
|
||||
).build()
|
||||
)
|
||||
|
||||
val videoMediaSource =
|
||||
(if (cacheFactory == null) DefaultMediaSourceFactory(context) else DefaultMediaSourceFactory(
|
||||
|
@ -465,6 +478,7 @@ class CS3IPlayer : IPlayer {
|
|||
)
|
||||
setHandleAudioBecomingNoisy(true)
|
||||
setPlaybackSpeed(playBackSpeed)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -550,6 +564,7 @@ class CS3IPlayer : IPlayer {
|
|||
currentWindow,
|
||||
playbackPosition,
|
||||
playBackSpeed,
|
||||
cacheSize = cacheSize,
|
||||
playWhenReady = isPlaying, // this keep the current state of the player
|
||||
cacheFactory = cacheFactory,
|
||||
subtitleOffset = currentSubtitleOffset
|
||||
|
@ -763,7 +778,7 @@ class CS3IPlayer : IPlayer {
|
|||
subtitleHelper.setActiveSubtitles(activeSubtitles.toSet())
|
||||
|
||||
if (simpleCache == null)
|
||||
simpleCache = getCache(context, cacheSize)
|
||||
simpleCache = getCache(context, simpleCacheSize)
|
||||
|
||||
val cacheFactory = CacheDataSource.Factory().apply {
|
||||
simpleCache?.let { setCache(it) }
|
||||
|
|
|
@ -123,6 +123,7 @@ class GeneratorPlayer : FullScreenPlayer() {
|
|||
if (isNextEpisode) 0L else getPos()
|
||||
},
|
||||
currentSubs,
|
||||
(if(sameEpisode) currentSelectedSubtitles else null) ?: getAutoSelectSubtitle(currentSubs, settings = true, downloads = true),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -433,16 +434,37 @@ class GeneratorPlayer : FullScreenPlayer() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun autoSelectFromSettings() {
|
||||
// auto select subtitle based of settings
|
||||
val langCode = preferredAutoSelectSubtitles
|
||||
if (!langCode.isNullOrEmpty() && player.getCurrentPreferredSubtitle() == null) {
|
||||
val lang = SubtitleHelper.fromTwoLettersToLanguage(langCode) ?: return
|
||||
private fun getAutoSelectSubtitle(
|
||||
subtitles: Set<SubtitleData>,
|
||||
settings: Boolean,
|
||||
downloads: Boolean
|
||||
): SubtitleData? {
|
||||
val langCode = preferredAutoSelectSubtitles ?: return null
|
||||
val lang = SubtitleHelper.fromTwoLettersToLanguage(langCode) ?: return null
|
||||
|
||||
currentSubs.firstOrNull { sub ->
|
||||
if (settings)
|
||||
subtitles.firstOrNull { sub ->
|
||||
sub.name.startsWith(lang)
|
||||
|| sub.name.trim() == langCode
|
||||
}?.let { sub ->
|
||||
return sub
|
||||
}
|
||||
if (downloads) {
|
||||
return subtitles.firstOrNull { sub ->
|
||||
(sub.origin == SubtitleOrigin.DOWNLOADED_FILE || sub.name == context?.getString(
|
||||
R.string.default_subtitles
|
||||
))
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun autoSelectFromSettings() {
|
||||
// auto select subtitle based of settings
|
||||
val langCode = preferredAutoSelectSubtitles
|
||||
|
||||
if (!langCode.isNullOrEmpty() && player.getCurrentPreferredSubtitle() == null) {
|
||||
getAutoSelectSubtitle(currentSubs, settings = true, downloads = false)?.let { sub ->
|
||||
context?.let { ctx ->
|
||||
if (setSubtitles(sub)) {
|
||||
player.reloadPlayer(ctx)
|
||||
|
@ -455,11 +477,7 @@ class GeneratorPlayer : FullScreenPlayer() {
|
|||
|
||||
private fun autoSelectFromDownloads() {
|
||||
if (player.getCurrentPreferredSubtitle() == null) {
|
||||
currentSubs.firstOrNull { sub ->
|
||||
(sub.origin == SubtitleOrigin.DOWNLOADED_FILE || sub.name == context?.getString(
|
||||
R.string.default_subtitles
|
||||
))
|
||||
}?.let { sub ->
|
||||
getAutoSelectSubtitle(currentSubs, settings = false, downloads = true)?.let { sub ->
|
||||
context?.let { ctx ->
|
||||
if (setSubtitles(sub)) {
|
||||
player.reloadPlayer(ctx)
|
||||
|
|
|
@ -95,6 +95,7 @@ interface IPlayer {
|
|||
data: ExtractorUri? = null,
|
||||
startPosition: Long? = null,
|
||||
subtitles : Set<SubtitleData>,
|
||||
subtitle : SubtitleData?,
|
||||
)
|
||||
|
||||
fun reloadPlayer(context: Context)
|
||||
|
|
Loading…
Reference in a new issue