From aa6a84cdb915fc34816e0b1cf5d5b9496f48ad0e 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 | 27 ++++++++++--------- 2 files changed, 17 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 7e4c47d4..0f54770f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt @@ -11,6 +11,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 @@ -29,6 +30,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 de926c76..cf12fab0 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 @@ -797,18 +797,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() {