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

Fix that the first video using the audio player gets skipped #4173

Merged
merged 1 commit into from
Jul 6, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class OnlinePlayerService : LifecycleService() {
* The [ExoPlayer] player. Followed tutorial [here](https://developer.android.com/codelabs/exoplayer-intro)
*/
var player: ExoPlayer? = null
private var playWhenReadyPlayer = true
private var isTransitioning = true

/**
* SponsorBlock Segment data
Expand Down Expand Up @@ -162,6 +162,7 @@ class OnlinePlayerService : LifecycleService() {
*/
private fun loadAudio(playerData: PlayerData) {
val (videoId, _, _, keepQueue, timestamp) = playerData
isTransitioning = true

lifecycleScope.launch(Dispatchers.IO) {
streams = runCatching {
Expand Down Expand Up @@ -205,7 +206,7 @@ class OnlinePlayerService : LifecycleService() {
streams?.let { onNewVideo?.invoke(it, videoId) }

player?.apply {
playWhenReady = playWhenReadyPlayer
playWhenReady = true
prepare()
}

Expand Down Expand Up @@ -255,15 +256,17 @@ class OnlinePlayerService : LifecycleService() {
override fun onPlaybackStateChanged(state: Int) {
when (state) {
Player.STATE_ENDED -> {
if (PlayerHelper.autoPlayEnabled) playNextVideo()
if (PlayerHelper.autoPlayEnabled && !isTransitioning) playNextVideo()
}

Player.STATE_IDLE -> {
onDestroy()
}

Player.STATE_BUFFERING -> {}
Player.STATE_READY -> {}
Player.STATE_READY -> {
isTransitioning = false
}
}
}

Expand Down