Skip to content

Commit

Permalink
Instrumenting PlayerService with logs
Browse files Browse the repository at this point in the history
  • Loading branch information
thetwom committed Oct 17, 2022
1 parent e8c0807 commit 379bb32
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app/src/main/java/de/moekadu/metronome/services/PlayerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ class PlayerService : LifecycleService() {
bpm = bpm.copy(bpm = bpm.bpm - speedLimiter.bpmIncrement.value!!)

if (myAction == PlaybackStateCompat.ACTION_PLAY) {
// Log.v("Metronome", "ActionReceiver:onReceive : set state to playing");
Log.v("Metronome", "ActionReceiver:onReceive : set state to playing on service ${this}")
startPlay()
} else if (myAction == PlaybackStateCompat.ACTION_PAUSE) {
// Log.v("Metronome", "ActionReceiver:onReceive : set state to pause");
Log.v("Metronome", "ActionReceiver:onReceive : set state to pause on service ${this}");
stopPlay()
}
}
Expand Down Expand Up @@ -196,18 +196,14 @@ class PlayerService : LifecycleService() {

mediaSession?.setCallback(object : MediaSessionCompat.Callback() {
override fun onPlay() {
// Log.v("Metronome", "mediaSession:onPlay()");
if (state != PlaybackStateCompat.STATE_PLAYING) {
startPlay()
}
Log.v("Metronome", "mediaSession:onPlay() on service ${this}");
startPlay()
super.onPlay()
}

override fun onPause() {
// Log.v("Metronome", "mediaSession:onPause()");
if (state == PlaybackStateCompat.STATE_PLAYING) {
stopPlay()
}
Log.v("Metronome", "mediaSession:onPause() on service ${this}");
stopPlay()
super.onPause()
}
})
Expand Down Expand Up @@ -293,6 +289,10 @@ class PlayerService : LifecycleService() {
}

fun startPlay() {
Log.v("Metronome", "PlayerService:startPlay : on service ${this}, playbackState before call=$state")
if (state == PlaybackStateCompat.STATE_PLAYING)
return

// Log.v("Metronome", "PlayerService:startPlay : setting playbackState")
playbackState = playbackStateBuilder.setState(
PlaybackStateCompat.STATE_PLAYING,
Expand All @@ -314,7 +314,9 @@ class PlayerService : LifecycleService() {
}

fun stopPlay() {
// Log.v("Metronome", "PlayerService:stopPlay")
Log.v("Metronome", "PlayerService:stopPlay : on service ${this}, playbackState before call=$state")
if (state == PlaybackStateCompat.STATE_PAUSED)
return

playbackState = playbackStateBuilder.setState(
PlaybackStateCompat.STATE_PAUSED,
Expand Down

0 comments on commit 379bb32

Please sign in to comment.