From 7adc6f6cb1d315a684a64f2cbbfd2bf8a2476c04 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Fri, 22 Apr 2022 21:01:29 +0200 Subject: [PATCH] fixed #958 --- .../cloudstream3/ui/ControllerActivity.kt | 21 ++++++++++++++----- .../cloudstream3/ui/player/GeneratorPlayer.kt | 1 - 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt index ef69ca0c..8e05dc27 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt @@ -21,6 +21,7 @@ import com.google.android.gms.cast.framework.media.uicontroller.UIController import com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.mvvm.Resource +import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.safeApiCall import com.lagradost.cloudstream3.sortSubs import com.lagradost.cloudstream3.sortUrls @@ -33,6 +34,7 @@ import com.lagradost.cloudstream3.utils.CastHelper.awaitLinks import com.lagradost.cloudstream3.utils.CastHelper.getMediaInfo import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.toKotlinObject +import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import org.json.JSONObject @@ -268,24 +270,33 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi if (meta != null && meta.episodes.size > meta.currentEpisodeIndex + 1) { val currentIdIndex = remoteMediaClient?.getItemIndex() ?: return val itemCount = remoteMediaClient?.mediaQueue?.itemCount + val index = meta.currentEpisodeIndex + 1 + val epData = meta.episodes[index] + + try { + val currentDuration = remoteMediaClient?.streamDuration + val currentPosition = remoteMediaClient?.approximateStreamPosition + if (currentDuration != null && currentPosition != null) + DataStoreHelper.setViewPos(epData.id, currentPosition, currentDuration) + } catch (e : Exception) { + logError(e) + } if (itemCount != null && itemCount - currentIdIndex == 1 && !isLoadingMore) { isLoadingMore = true ioSafe { - val index = meta.currentEpisodeIndex + 1 - val epData = meta.episodes[index] val currentLinks = mutableSetOf() val currentSubs = mutableSetOf() val generator = RepoLinkGenerator(listOf(epData)) val isSuccessful = safeApiCall { - generator.generateLinks(false, true, - { + generator.generateLinks(clearCache = false, isCasting = true, + callback = { it.first?.let { link -> currentLinks.add(link) } - }, { + }, subtitleCallback = { currentSubs.add(it) }) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 116e0830..ea21d63e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -393,7 +393,6 @@ class GeneratorPlayer : FullScreenPlayer() { override fun playerPositionChanged(posDur: Pair) { val (position, duration) = posDur viewModel.getId()?.let { - println("SET VIEW ID: $it ($position/$duration)") DataStoreHelper.setViewPos(it, position, duration) } val percentage = position * 100L / duration