Skip to content

Commit

Permalink
Fix crash in Urgent.fm player
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Dec 12, 2023
1 parent 634c4f6 commit 2d70dbd
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class MediaNotificationBuilder {

Notification buildNotification(MediaSessionCompat mediaSession) {
MediaControllerCompat controller = mediaSession.getController();
var playbackState = controller.getPlaybackState();
if (playbackState == null) {
return null; // Nothing we can do currently.
}

// Construct the actual notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ChannelCreator.URGENT_CHANNEL);
Expand All @@ -65,10 +69,10 @@ Notification buildNotification(MediaSessionCompat mediaSession) {
.setShowActionsInCompactView(0);

// Construct the play/pause button.
boolean isPlaying = controller.getPlaybackState().getState() == PlaybackStateCompat.STATE_PLAYING;
boolean isConnecting = controller.getPlaybackState().getState() == PlaybackStateCompat.STATE_CONNECTING
|| controller.getPlaybackState().getState() == PlaybackStateCompat.STATE_BUFFERING;
boolean isError = controller.getPlaybackState().getState() == PlaybackStateCompat.STATE_ERROR;
boolean isPlaying = playbackState.getState() == PlaybackStateCompat.STATE_PLAYING;
boolean isConnecting = playbackState.getState() == PlaybackStateCompat.STATE_CONNECTING
|| playbackState.getState() == PlaybackStateCompat.STATE_BUFFERING;
boolean isError = playbackState.getState() == PlaybackStateCompat.STATE_ERROR;
if (isPlaying || isConnecting) {
builder.addAction(new NotificationCompat.Action(
R.drawable.noti_ic_stop,
Expand Down

0 comments on commit 2d70dbd

Please sign in to comment.