Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow resuming playback after disconnect #4746

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/src/main/java/com/github/libretube/extensions/Player.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.libretube.extensions

Check failure on line 1 in app/src/main/java/com/github/libretube/extensions/Player.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 File must end with a newline (\n) Raw Output: app/src/main/java/com/github/libretube/extensions/Player.kt:1:1: error: File must end with a newline (\n) (standard:final-newline)

import androidx.media3.common.Player

fun Player.togglePlayPauseState() {
when {
playerError != null -> {
prepare()
play()
}

!isPlaying && playbackState == Player.STATE_ENDED -> {

Check failure on line 12 in app/src/main/java/com/github/libretube/extensions/Player.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Unexpected indentation (7) (should be 8) Raw Output: app/src/main/java/com/github/libretube/extensions/Player.kt:12:1: error: Unexpected indentation (7) (should be 8) (standard:indent)
seekTo(0)
}

!isPlaying && !isLoading -> play()
else -> pause()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import com.github.libretube.extensions.serializableExtra
import com.github.libretube.extensions.setMetadata
import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.extensions.togglePlayPauseState
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.BackgroundHelper
import com.github.libretube.helpers.ImageHelper
Expand Down Expand Up @@ -391,14 +392,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerBinding.autoPlay.isVisible = true

binding.playImageView.setOnClickListener {
when {
!exoPlayer.isPlaying && exoPlayer.playbackState == Player.STATE_ENDED -> {
exoPlayer.seekTo(0)
}

!exoPlayer.isPlaying -> exoPlayer.play()
else -> exoPlayer.pause()
}
exoPlayer.togglePlayPauseState()
}

// video description and chapters toggle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.github.libretube.extensions.dpToPx
import com.github.libretube.extensions.normalize
import com.github.libretube.extensions.round
import com.github.libretube.extensions.seekBy
import com.github.libretube.extensions.togglePlayPauseState
import com.github.libretube.helpers.AudioHelper
import com.github.libretube.helpers.BrightnessHelper
import com.github.libretube.helpers.PlayerHelper
Expand Down Expand Up @@ -156,14 +157,7 @@ open class CustomExoPlayerView(
}

binding.playPauseBTN.setOnClickListener {
when {
player?.isPlaying == false && player?.playbackState == Player.STATE_ENDED -> {
player?.seekTo(0)
}

player?.isPlaying == false && player?.isLoading == false -> player?.play()
else -> player?.pause()
}
player?.togglePlayPauseState()
}

player?.addListener(object : Player.Listener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class NowPlayingNotification(
}

PLAY_PAUSE -> {
if (player.playerError != null) player.prepare()
if (player.isPlaying) player.pause() else player.play()
}

Expand Down
Loading