Skip to content

Commit

Permalink
fix: currentPlayable currentSongIndex not changing when we change son…
Browse files Browse the repository at this point in the history
…g using notification
  • Loading branch information
GautamCoder4019k committed Jan 21, 2025
1 parent 6d18d95 commit d84464b
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.Service.STOP_FOREGROUND_DETACH
import android.os.Build
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_AUTO_TRANSITION
import com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT
import org.listenbrainz.android.util.Log

class BrainzPlayerEventListener(
Expand All @@ -26,10 +28,15 @@ class BrainzPlayerEventListener(
reason: Int
) {
super.onPositionDiscontinuity(oldPosition, newPosition, reason)
//updating current playing index when song auto transitions
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
brainzPlayerService.appPreferences.currentPlayable =
brainzPlayerService.appPreferences.currentPlayable?.copy(currentSongIndex = newPosition.mediaItemIndex)

//updating current playing index when song auto transitions or song change from notification
when (reason) {
DISCONTINUITY_REASON_SEEK_ADJUSTMENT, DISCONTINUITY_REASON_AUTO_TRANSITION -> {
brainzPlayerService.appPreferences.currentPlayable =
brainzPlayerService.appPreferences.currentPlayable?.copy(currentSongIndex = newPosition.mediaItemIndex)
}

else -> {}
}
}

Expand Down

0 comments on commit d84464b

Please sign in to comment.