From 9df81953d1bc4527aca07821342282b14fc78620 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 25 Oct 2018 19:20:38 +0200 Subject: [PATCH] catch exceptions thrown at setPlaybackState --- .../musicplayer/services/MusicService.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt index 35d8c5e6..3b9999a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -424,9 +424,12 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr } val playbackState = if (getIsPlaying()) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED - mediaSession!!.setPlaybackState(PlaybackStateCompat.Builder() - .setState(playbackState, PLAYBACK_POSITION_UNKNOWN, 1.0f) - .build()) + try { + mediaSession!!.setPlaybackState(PlaybackStateCompat.Builder() + .setState(playbackState, PLAYBACK_POSITION_UNKNOWN, 1.0f) + .build()) + } catch (ignored: IllegalStateException) { + } } private fun getContentIntent(): PendingIntent {