From b7faad8742c20a1df248c08827dcbec62217e470 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 14 Mar 2018 10:11:16 +0100 Subject: [PATCH] catch and show exceptions thrown at playing sounds --- .../clock/dialogs/SelectAlarmSoundDialog.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt index 5dc4c4fa..d30259b7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.clock.activities.SimpleActivity import com.simplemobiletools.clock.extensions.getAlarms import com.simplemobiletools.clock.models.AlarmSound import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showErrorToast import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.* class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: String, val audioStream: Int, val callback: (alarmSound: AlarmSound) -> Unit) { @@ -26,12 +27,16 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin isChecked = alarmSound.uri == currentUri id = index setOnClickListener { - mediaPlayer.stop() - mediaPlayer = MediaPlayer().apply { - setAudioStreamType(audioStream) - setDataSource(context, Uri.parse(alarmSound.uri)) - prepare() - start() + try { + mediaPlayer.stop() + mediaPlayer = MediaPlayer().apply { + setAudioStreamType(audioStream) + setDataSource(context, Uri.parse(alarmSound.uri)) + prepare() + start() + } + } catch (e: Exception) { + activity.showErrorToast(e) } } }