Merge remote-tracking branch 'origin/master'

This commit is contained in:
LagradOst 2022-06-19 01:03:33 +02:00
commit 95767fb523
3 changed files with 13 additions and 6 deletions

View file

@ -187,6 +187,9 @@ class CS3IPlayer : IPlayer {
} }
var currentSubtitles: SubtitleData? = null var currentSubtitles: SubtitleData? = null
/**
* @return True if the player should be reloaded
* */
override fun setPreferredSubtitles(subtitle: SubtitleData?): Boolean { override fun setPreferredSubtitles(subtitle: SubtitleData?): Boolean {
Log.i(TAG, "setPreferredSubtitles init $subtitle") Log.i(TAG, "setPreferredSubtitles init $subtitle")
currentSubtitles = subtitle currentSubtitles = subtitle
@ -202,7 +205,6 @@ class CS3IPlayer : IPlayer {
SubtitleStatus.REQUIRES_RELOAD -> { SubtitleStatus.REQUIRES_RELOAD -> {
Log.i(TAG, "setPreferredSubtitles REQUIRES_RELOAD") Log.i(TAG, "setPreferredSubtitles REQUIRES_RELOAD")
return@let true return@let true
// reloadPlayer(context)
} }
SubtitleStatus.IS_ACTIVE -> { SubtitleStatus.IS_ACTIVE -> {
Log.i(TAG, "setPreferredSubtitles IS_ACTIVE") Log.i(TAG, "setPreferredSubtitles IS_ACTIVE")
@ -227,7 +229,6 @@ class CS3IPlayer : IPlayer {
//} //}
} }
SubtitleStatus.NOT_FOUND -> { SubtitleStatus.NOT_FOUND -> {
// not found
Log.i(TAG, "setPreferredSubtitles NOT_FOUND") Log.i(TAG, "setPreferredSubtitles NOT_FOUND")
return@let true return@let true
} }
@ -269,7 +270,7 @@ class CS3IPlayer : IPlayer {
subtitleHelper.setSubStyle(style) subtitleHelper.setSubStyle(style)
} }
private fun saveData() { override fun saveData() {
Log.i(TAG, "saveData") Log.i(TAG, "saveData")
updatedTime() updatedTime()
@ -511,6 +512,7 @@ class CS3IPlayer : IPlayer {
mediaItem mediaItem
) )
println("PLAYBACK POS $playbackPosition")
return exoPlayerBuilder.build().apply { return exoPlayerBuilder.build().apply {
setPlayWhenReady(playWhenReady) setPlayWhenReady(playWhenReady)
seekTo(currentWindow, playbackPosition) seekTo(currentWindow, playbackPosition)

View file

@ -375,8 +375,10 @@ class GeneratorPlayer : FullScreenPlayer() {
setSubtitles(subtitleData) setSubtitles(subtitleData)
// this is used instead of observe, because observe is too slow // this is used instead of observe, because observe is too slow
val subs = currentSubs.toMutableSet() val subs = currentSubs + subtitleData
subs.add(subtitleData)
// Save current time as to not reset player to 00:00
player.saveData()
player.setActiveSubtitles(subs) player.setActiveSubtitles(subs)
player.reloadPlayer(ctx) player.reloadPlayer(ctx)
@ -774,11 +776,11 @@ class GeneratorPlayer : FullScreenPlayer() {
private fun autoSelectFromSettings(): Boolean { private fun autoSelectFromSettings(): Boolean {
// auto select subtitle based of settings // auto select subtitle based of settings
val langCode = preferredAutoSelectSubtitles val langCode = preferredAutoSelectSubtitles
if (!langCode.isNullOrEmpty() && player.getCurrentPreferredSubtitle() == null) { if (!langCode.isNullOrEmpty() && player.getCurrentPreferredSubtitle() == null) {
getAutoSelectSubtitle(currentSubs, settings = true, downloads = false)?.let { sub -> getAutoSelectSubtitle(currentSubs, settings = true, downloads = false)?.let { sub ->
context?.let { ctx -> context?.let { ctx ->
if (setSubtitles(sub)) { if (setSubtitles(sub)) {
player.saveData()
player.reloadPlayer(ctx) player.reloadPlayer(ctx)
player.handleEvent(CSPlayerEvent.Play) player.handleEvent(CSPlayerEvent.Play)
return true return true
@ -794,6 +796,7 @@ class GeneratorPlayer : FullScreenPlayer() {
getAutoSelectSubtitle(currentSubs, settings = false, downloads = true)?.let { sub -> getAutoSelectSubtitle(currentSubs, settings = false, downloads = true)?.let { sub ->
context?.let { ctx -> context?.let { ctx ->
if (setSubtitles(sub)) { if (setSubtitles(sub)) {
player.saveData()
player.reloadPlayer(ctx) player.reloadPlayer(ctx)
player.handleEvent(CSPlayerEvent.Play) player.handleEvent(CSPlayerEvent.Play)
return true return true

View file

@ -90,6 +90,8 @@ interface IPlayer {
) )
fun updateSubtitleStyle(style: SaveCaptionStyle) fun updateSubtitleStyle(style: SaveCaptionStyle)
fun saveData()
fun loadPlayer( fun loadPlayer(
context: Context, context: Context,
sameEpisode: Boolean, sameEpisode: Boolean,