don't initialize exoplayer, if view model exists and player is ready

this prevents the media being reloaded, when the app is moved to the background and to the foreground again
This commit is contained in:
Jannik 2020-12-28 20:45:52 +01:00
parent 800c2a144c
commit 7a5f90cb82
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
2 changed files with 14 additions and 6 deletions

View File

@ -64,8 +64,12 @@ class PlayerActivity : AppCompatActivity() {
model.currentEpisodeChangedListener.add { onMediaChanged() }
gestureDetector = GestureDetectorCompat(this, PlayerGestureListener())
controller = video_view.findViewById(R.id.exo_controller)
controller.isAnimationEnabled = false // disable controls (time-bar) animation
initGUI()
initActions()
initExoPlayer() // call in onCreate, exoplayer lives in view model
}
override fun onStart() {
@ -113,16 +117,20 @@ class PlayerActivity : AppCompatActivity() {
this.finish()
}
initExoPlayer()
initVideoView()
initTimeUpdates()
// if the player is ready or buffering we can simply play the file again, else do nothing
if ((model.player.playbackState == ExoPlayer.STATE_READY || model.player.playbackState == ExoPlayer.STATE_BUFFERING)
) {
model.player.play()
}
}
// TODO if view model was not destroyed, don't start a new media
/**
* set play when ready and listeners
*/
private fun initExoPlayer() {
controller = video_view.findViewById(R.id.exo_controller)
controller.isAnimationEnabled = false // disable controls (time-bar) animation
model.player.playWhenReady = playWhenReady
model.player.addListener(object : Player.EventListener {
override fun onPlaybackStateChanged(state: Int) {

View File

@ -69,7 +69,7 @@ data class Info(
* number = episode number (0..n)
*/
data class Episode(
val id: Int = 0,
val id: Int = -1,
val streams: MutableList<Stream> = mutableListOf(),
val title: String = "",
val posterUrl: String = "",