From 060d983d2e0becf4500d7f66bd2d1afa481fced5 Mon Sep 17 00:00:00 2001 From: reduplicated <110570621+reduplicated@users.noreply.github.com> Date: Mon, 8 Aug 2022 14:37:46 +0200 Subject: [PATCH] Fix chromecasting regression --- .../lagradost/cloudstream3/CommonActivity.kt | 2 ++ .../ui/result/ResultViewModel2.kt | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt index 0ed802ba..6369721d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt @@ -10,6 +10,7 @@ import android.util.Log import android.view.* import android.widget.TextView import android.widget.Toast +import androidx.annotation.MainThread import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView @@ -26,6 +27,7 @@ import org.schabi.newpipe.extractor.NewPipe import java.util.* object CommonActivity { + @MainThread fun Activity?.getCastSession(): CastSession? { return (this as MainActivity?)?.mSessionManager?.currentCastSession } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt index 90ebb52f..1984f0f5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt @@ -43,6 +43,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.isConnectedToChromecast import com.lagradost.cloudstream3.utils.CastHelper.startCast import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioWork +import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.DataStoreHelper.getDub import com.lagradost.cloudstream3.utils.DataStoreHelper.getResultEpisode @@ -798,18 +799,21 @@ class ResultViewModel2 : ViewModel() { val response = currentResponse ?: return val eps = currentEpisodes[currentIndex ?: return] ?: return - activity.getCastSession()?.startCast( - response.apiName, - response.isMovie(), - response.name, - response.posterUrl, - result.index, - eps, - links, - subs, - startTime = result.getRealPosition(), - startIndex = startIndex - ) + // Main needed because getCastSession needs to be on main thread + main { + activity.getCastSession()?.startCast( + response.apiName, + response.isMovie(), + response.name, + response.posterUrl, + result.index, + eps, + links, + subs, + startTime = result.getRealPosition(), + startIndex = startIndex + ) + } } fun cancelLinks() {