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:
parent
800c2a144c
commit
7a5f90cb82
@ -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) {
|
||||
|
@ -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 = "",
|
||||
|
Loading…
Reference in New Issue
Block a user