mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
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 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
|
||||||
|
private var simpleCacheSize = 100L * 1024L * 1024L
|
||||||
|
|
||||||
private val seekActionTime = 30000L
|
private val seekActionTime = 30000L
|
||||||
|
|
||||||
|
@ -143,13 +144,14 @@ class CS3IPlayer : IPlayer {
|
||||||
link: ExtractorLink?,
|
link: ExtractorLink?,
|
||||||
data: ExtractorUri?,
|
data: ExtractorUri?,
|
||||||
startPosition: Long?,
|
startPosition: Long?,
|
||||||
subtitles: Set<SubtitleData>
|
subtitles: Set<SubtitleData>,
|
||||||
|
subtitle: SubtitleData?
|
||||||
) {
|
) {
|
||||||
Log.i(TAG, "loadPlayer")
|
Log.i(TAG, "loadPlayer")
|
||||||
if (sameEpisode) {
|
if (sameEpisode) {
|
||||||
saveData()
|
saveData()
|
||||||
} else {
|
} else {
|
||||||
currentSubtitles = null
|
currentSubtitles = subtitle
|
||||||
playbackPosition = 0
|
playbackPosition = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,6 +422,7 @@ class CS3IPlayer : IPlayer {
|
||||||
playbackPosition: Long,
|
playbackPosition: Long,
|
||||||
playBackSpeed: Float,
|
playBackSpeed: Float,
|
||||||
subtitleOffset: Long,
|
subtitleOffset: Long,
|
||||||
|
cacheSize: Long,
|
||||||
playWhenReady: Boolean = true,
|
playWhenReady: Boolean = true,
|
||||||
cacheFactory: CacheDataSource.Factory? = null,
|
cacheFactory: CacheDataSource.Factory? = null,
|
||||||
trackSelector: TrackSelector? = null,
|
trackSelector: TrackSelector? = null,
|
||||||
|
@ -446,6 +449,16 @@ class CS3IPlayer : IPlayer {
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
}
|
}
|
||||||
.setTrackSelector(trackSelector ?: getTrackSelector(context))
|
.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 =
|
val videoMediaSource =
|
||||||
(if (cacheFactory == null) DefaultMediaSourceFactory(context) else DefaultMediaSourceFactory(
|
(if (cacheFactory == null) DefaultMediaSourceFactory(context) else DefaultMediaSourceFactory(
|
||||||
|
@ -465,6 +478,7 @@ class CS3IPlayer : IPlayer {
|
||||||
)
|
)
|
||||||
setHandleAudioBecomingNoisy(true)
|
setHandleAudioBecomingNoisy(true)
|
||||||
setPlaybackSpeed(playBackSpeed)
|
setPlaybackSpeed(playBackSpeed)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -550,6 +564,7 @@ class CS3IPlayer : IPlayer {
|
||||||
currentWindow,
|
currentWindow,
|
||||||
playbackPosition,
|
playbackPosition,
|
||||||
playBackSpeed,
|
playBackSpeed,
|
||||||
|
cacheSize = cacheSize,
|
||||||
playWhenReady = isPlaying, // this keep the current state of the player
|
playWhenReady = isPlaying, // this keep the current state of the player
|
||||||
cacheFactory = cacheFactory,
|
cacheFactory = cacheFactory,
|
||||||
subtitleOffset = currentSubtitleOffset
|
subtitleOffset = currentSubtitleOffset
|
||||||
|
@ -763,7 +778,7 @@ class CS3IPlayer : IPlayer {
|
||||||
subtitleHelper.setActiveSubtitles(activeSubtitles.toSet())
|
subtitleHelper.setActiveSubtitles(activeSubtitles.toSet())
|
||||||
|
|
||||||
if (simpleCache == null)
|
if (simpleCache == null)
|
||||||
simpleCache = getCache(context, cacheSize)
|
simpleCache = getCache(context, simpleCacheSize)
|
||||||
|
|
||||||
val cacheFactory = CacheDataSource.Factory().apply {
|
val cacheFactory = CacheDataSource.Factory().apply {
|
||||||
simpleCache?.let { setCache(it) }
|
simpleCache?.let { setCache(it) }
|
||||||
|
|
|
@ -123,6 +123,7 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
if (isNextEpisode) 0L else getPos()
|
if (isNextEpisode) 0L else getPos()
|
||||||
},
|
},
|
||||||
currentSubs,
|
currentSubs,
|
||||||
|
(if(sameEpisode) currentSelectedSubtitles else null) ?: getAutoSelectSubtitle(currentSubs, settings = true, downloads = true),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,16 +434,37 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun autoSelectFromSettings() {
|
private fun getAutoSelectSubtitle(
|
||||||
// auto select subtitle based of settings
|
subtitles: Set<SubtitleData>,
|
||||||
val langCode = preferredAutoSelectSubtitles
|
settings: Boolean,
|
||||||
if (!langCode.isNullOrEmpty() && player.getCurrentPreferredSubtitle() == null) {
|
downloads: Boolean
|
||||||
val lang = SubtitleHelper.fromTwoLettersToLanguage(langCode) ?: return
|
): 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.startsWith(lang)
|
||||||
|| sub.name.trim() == langCode
|
|| sub.name.trim() == langCode
|
||||||
}?.let { sub ->
|
}?.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 ->
|
context?.let { ctx ->
|
||||||
if (setSubtitles(sub)) {
|
if (setSubtitles(sub)) {
|
||||||
player.reloadPlayer(ctx)
|
player.reloadPlayer(ctx)
|
||||||
|
@ -455,11 +477,7 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
|
|
||||||
private fun autoSelectFromDownloads() {
|
private fun autoSelectFromDownloads() {
|
||||||
if (player.getCurrentPreferredSubtitle() == null) {
|
if (player.getCurrentPreferredSubtitle() == null) {
|
||||||
currentSubs.firstOrNull { sub ->
|
getAutoSelectSubtitle(currentSubs, settings = false, downloads = true)?.let { sub ->
|
||||||
(sub.origin == SubtitleOrigin.DOWNLOADED_FILE || sub.name == context?.getString(
|
|
||||||
R.string.default_subtitles
|
|
||||||
))
|
|
||||||
}?.let { sub ->
|
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
if (setSubtitles(sub)) {
|
if (setSubtitles(sub)) {
|
||||||
player.reloadPlayer(ctx)
|
player.reloadPlayer(ctx)
|
||||||
|
|
|
@ -95,6 +95,7 @@ interface IPlayer {
|
||||||
data: ExtractorUri? = null,
|
data: ExtractorUri? = null,
|
||||||
startPosition: Long? = null,
|
startPosition: Long? = null,
|
||||||
subtitles : Set<SubtitleData>,
|
subtitles : Set<SubtitleData>,
|
||||||
|
subtitle : SubtitleData?,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun reloadPlayer(context: Context)
|
fun reloadPlayer(context: Context)
|
||||||
|
|
Loading…
Reference in a new issue