release player in PlayerVIewModel onCleared()
this fixes playback after the activity has been destroyed, while being in background
This commit is contained in:
parent
7845770067
commit
b3ce43c614
|
@ -118,6 +118,7 @@ class PlayerActivity : AppCompatActivity() {
|
|||
initTimeUpdates()
|
||||
}
|
||||
|
||||
// TODO if view model was not destroyed, don't start a new media
|
||||
private fun initExoPlayer() {
|
||||
controller = video_view.findViewById(R.id.exo_controller)
|
||||
controller.isAnimationEnabled = false // disable controls (time-bar) animation
|
||||
|
@ -222,10 +223,8 @@ class PlayerActivity : AppCompatActivity() {
|
|||
playbackPosition = model.player.currentPosition
|
||||
currentWindow = model.player.currentWindowIndex
|
||||
playWhenReady = model.player.playWhenReady
|
||||
model.player.release()
|
||||
model.player.pause()
|
||||
timerUpdates.cancel()
|
||||
|
||||
Log.d(javaClass.name, "Released player")
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.mosad.teapod.player
|
|||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import com.google.android.exoplayer2.C
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
|
@ -42,6 +43,13 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
|||
var currentLanguage: Locale = Locale.ROOT
|
||||
internal set
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
player.release()
|
||||
|
||||
Log.d(javaClass.name, "Released player")
|
||||
}
|
||||
|
||||
fun loadMedia(mediaId: Int, episodeId: Int) {
|
||||
runBlocking {
|
||||
media = AoDParser.getMediaById(mediaId)
|
||||
|
|
Loading…
Reference in New Issue