Fixed online subs resetting progress (for real this time)

This commit is contained in:
Blatzar 2022-06-18 19:10:32 +02:00
parent b619ee9bf8
commit cc7d7ec478
3 changed files with 16 additions and 12 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
@ -199,15 +202,11 @@ class CS3IPlayer : IPlayer {
) )
} else { } else {
when (subtitleHelper.subtitleStatus(subtitle)) { when (subtitleHelper.subtitleStatus(subtitle)) {
SubtitleStatus.REQUIRES_RELOAD -> {
// Uncommenting this will lead to online subtitles resetting player to 00:00 on reload Log.i(TAG, "setPreferredSubtitles REQUIRES_RELOAD")
return@let true
// SubtitleStatus.REQUIRES_RELOAD -> { }
// Log.i(TAG, "setPreferredSubtitles REQUIRES_RELOAD") SubtitleStatus.IS_ACTIVE -> {
// return@let true
// // reloadPlayer(context)
// }
SubtitleStatus.IS_ACTIVE, SubtitleStatus.REQUIRES_RELOAD -> {
Log.i(TAG, "setPreferredSubtitles IS_ACTIVE") Log.i(TAG, "setPreferredSubtitles IS_ACTIVE")
trackSelector.setParameters( trackSelector.setParameters(
@ -230,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
} }
@ -272,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()

View file

@ -376,6 +376,9 @@ class GeneratorPlayer : FullScreenPlayer() {
// 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 + subtitleData val subs = currentSubs + 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)
@ -773,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
@ -793,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,