From 2dba635e2f01a9e9264eeea814c42d9ea1543fd1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 14 Sep 2018 14:02:26 +0200 Subject: [PATCH] catch exceptions thrown at setting up mediaplayer --- .../clock/activities/ReminderActivity.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt index d9393df5..08f69c30 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt @@ -146,13 +146,17 @@ class ReminderActivity : SimpleActivity() { } val soundUri = Uri.parse(if (alarm != null) alarm!!.soundUri else config.timerSoundUri) - mediaPlayer = MediaPlayer().apply { - setAudioStreamType(AudioManager.STREAM_ALARM) - setDataSource(this@ReminderActivity, soundUri) - setVolume(lastVolumeValue, lastVolumeValue) - isLooping = true - prepare() - start() + try { + mediaPlayer = MediaPlayer().apply { + setAudioStreamType(AudioManager.STREAM_ALARM) + setDataSource(this@ReminderActivity, soundUri) + setVolume(lastVolumeValue, lastVolumeValue) + isLooping = true + prepare() + start() + } + } catch (e: Exception) { + showErrorToast(e) } if (config.increaseVolumeGradually) {