Skip to content

Commit

Permalink
fix: player lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
RadiationX committed Dec 27, 2022
1 parent 2b2aa6d commit 1bb4e0b
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.devbrackets.android.exomedia.ui.widget.VideoControlsCore
import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.analytics.AnalyticsListener
import com.google.android.exoplayer2.source.MediaSourceEventListener
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -162,6 +163,8 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {

private var pictureInPictureParams: PictureInPictureParams.Builder? = null

private var releaseDataJob: Job? = null

private fun getStatisticByDomain(host: String): MutableList<Pair<AnalyticsQuality, Long>> {
if (!loadingStatistics.contains(host)) {
loadingStatistics[host] = mutableListOf()
Expand Down Expand Up @@ -305,10 +308,6 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {
}
handleIntent(intent)
updateUiFlags()

releaseInteractor.observeFull(releaseData.id, releaseData.code).onEach {
releaseData = it
}.launchIn(lifecycleScope)
}

override fun onNewIntent(intent: Intent?) {
Expand Down Expand Up @@ -346,7 +345,10 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {
binding.player.setOnCompletionListener(null)
binding.player.setOnVideoSizedChangedListener(null)
binding.player.setAnalyticsListener(null)
unregisterReceiver(mReceiver)
try {
unregisterReceiver(mReceiver)
} catch (ignore: Exception) {
}

videoControls?.apply {
setOpeningListener(null)
Expand Down Expand Up @@ -401,6 +403,11 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {
this.currentEpisodeId = episodeId
this.currentQuality = quality
this.playFlag = playFlag

releaseDataJob?.cancel()
releaseDataJob = releaseInteractor.observeFull(releaseData.id, releaseData.code).onEach {
releaseData = it
}.launchIn(lifecycleScope)
}

private fun handleIntent(intent: Intent) {
Expand Down

0 comments on commit 1bb4e0b

Please sign in to comment.