Make voice note playback log statement more readable.

This commit is contained in:
Nicholas Tinsley
2023-10-04 10:32:23 -04:00
parent b74a431ac9
commit 9a249b0dec

View File

@@ -115,24 +115,23 @@ public class VoiceNotePlaybackService extends MediaSessionService {
@Override @Override
public void onPlaybackStateChanged(int playbackState) { public void onPlaybackStateChanged(int playbackState) {
Log.d(TAG, "[onPlaybackStateChanged] playbackState: " + playbackState);
boolean playWhenReady = player.getPlayWhenReady(); boolean playWhenReady = player.getPlayWhenReady();
Log.d(TAG, "[onPlaybackStateChanged] playbackState: " + playbackStateToString(playbackState) + "\tplayWhenReady: " + playWhenReady);
switch (playbackState) { switch (playbackState) {
case Player.STATE_BUFFERING: case Player.STATE_BUFFERING, Player.STATE_READY -> {
case Player.STATE_READY:
if (!playWhenReady) { if (!playWhenReady) {
stopForeground(false); stopForeground(false);
} else { } else {
sendViewedReceiptForCurrentWindowIndex(); sendViewedReceiptForCurrentWindowIndex();
} }
break; }
case Player.STATE_ENDED: case Player.STATE_ENDED -> {
if (previousPlaybackState == Player.STATE_READY) { if (previousPlaybackState == Player.STATE_READY) {
player.clearMediaItems(); player.clearMediaItems();
} }
break; }
default: default -> {
}
} }
previousPlaybackState = playbackState; previousPlaybackState = playbackState;
} }
@@ -361,4 +360,14 @@ public class VoiceNotePlaybackService extends MediaSessionService {
Log.e(TAG, "Could not start VoiceNotePlaybackService, encountered a ForegroundServiceStartNotAllowedException."); Log.e(TAG, "Could not start VoiceNotePlaybackService, encountered a ForegroundServiceStartNotAllowedException.");
} }
} }
private String playbackStateToString(int playbackState) {
return switch (playbackState) {
case Player.STATE_IDLE -> "Player.STATE_IDLE";
case Player.STATE_BUFFERING -> "Player.STATE_BUFFERING";
case Player.STATE_READY -> "Player.STATE_READY";
case Player.STATE_ENDED -> "Player.STATE_ENDED";
default -> "UNKNOWN(" + playbackState + ")";
};
}
} }