catch and show exceptions thrown at playing sounds
This commit is contained in:
parent
5e564bfa25
commit
b7faad8742
|
@ -11,6 +11,7 @@ import com.simplemobiletools.clock.activities.SimpleActivity
|
||||||
import com.simplemobiletools.clock.extensions.getAlarms
|
import com.simplemobiletools.clock.extensions.getAlarms
|
||||||
import com.simplemobiletools.clock.models.AlarmSound
|
import com.simplemobiletools.clock.models.AlarmSound
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.*
|
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) {
|
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
|
isChecked = alarmSound.uri == currentUri
|
||||||
id = index
|
id = index
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
mediaPlayer.stop()
|
try {
|
||||||
mediaPlayer = MediaPlayer().apply {
|
mediaPlayer.stop()
|
||||||
setAudioStreamType(audioStream)
|
mediaPlayer = MediaPlayer().apply {
|
||||||
setDataSource(context, Uri.parse(alarmSound.uri))
|
setAudioStreamType(audioStream)
|
||||||
prepare()
|
setDataSource(context, Uri.parse(alarmSound.uri))
|
||||||
start()
|
prepare()
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
activity.showErrorToast(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue