Skip to content

Commit

Permalink
fix: Casting method update + crash fix
Browse files Browse the repository at this point in the history
- Update casting method for initialization
- Release casting onPause()
  • Loading branch information
omerhabib26 committed Aug 27, 2024
1 parent c0cd6de commit 4f18de1
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ class EncodedVideoUnitViewModel(
initPlayer()

val executor = Executors.newSingleThreadExecutor()
CastContext.getSharedInstance(context, executor).addOnCompleteListener {
it.result?.let { castContext ->
castPlayer = CastPlayer(castContext)
}
CastContext.getSharedInstance(context, executor).result?.let { castContext ->
castPlayer = CastPlayer(castContext)
}
}

Expand All @@ -119,8 +117,12 @@ class EncodedVideoUnitViewModel(

override fun onPause(owner: LifecycleOwner) {
super.onPause(owner)
exoPlayer?.removeListener(exoPlayerListener)
exoPlayer?.pause()
if (isCastActive) {
getActivePlayer()?.release()
} else {
exoPlayer?.removeListener(exoPlayerListener)
exoPlayer?.pause()
}
}

fun getActivePlayer(): Player? {
Expand Down

0 comments on commit 4f18de1

Please sign in to comment.