just reset the mediaplayer in SelectAlarmSoundDialog, dont recreate it
This commit is contained in:
parent
86f99b961b
commit
25f27d801c
2 changed files with 32 additions and 25 deletions
|
@ -7,7 +7,7 @@ buildscript {
|
|||
propMinSdkVersion = 16
|
||||
propTargetSdkVersion = propCompileSdkVersion
|
||||
propVersionCode = 1
|
||||
propVersionName = '4.4.13'
|
||||
propVersionName = '4.4.14'
|
||||
kotlin_version = '1.2.51'
|
||||
support_libs = '27.1.1'
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class SelectAlarmSoundDialog(val activity: BaseSimpleActivity, val currentUri: S
|
|||
private val view = activity.layoutInflater.inflate(R.layout.dialog_select_alarm_sound, null)
|
||||
private var systemAlarmSounds = ArrayList<AlarmSound>()
|
||||
private var yourAlarmSounds = ArrayList<AlarmSound>()
|
||||
private var mediaPlayer = MediaPlayer()
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
private val config = activity.baseConfig
|
||||
private val dialog: AlertDialog
|
||||
|
||||
|
@ -45,8 +45,8 @@ class SelectAlarmSoundDialog(val activity: BaseSimpleActivity, val currentUri: S
|
|||
addYourAlarms()
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setOnDismissListener { mediaPlayer.stop() }
|
||||
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
|
||||
.setOnDismissListener { mediaPlayer?.stop() }
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
|
@ -102,8 +102,9 @@ class SelectAlarmSoundDialog(val activity: BaseSimpleActivity, val currentUri: S
|
|||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
private fun alarmClicked(alarmSound: AlarmSound) = when {
|
||||
alarmSound.uri == SILENT -> mediaPlayer.stop()
|
||||
private fun alarmClicked(alarmSound: AlarmSound) {
|
||||
when {
|
||||
alarmSound.uri == SILENT -> mediaPlayer?.stop()
|
||||
alarmSound.id == ADD_NEW_SOUND_ID -> {
|
||||
val action = if (isKitkatPlus()) Intent.ACTION_OPEN_DOCUMENT else Intent.ACTION_GET_CONTENT
|
||||
Intent(action).apply {
|
||||
|
@ -117,11 +118,16 @@ class SelectAlarmSoundDialog(val activity: BaseSimpleActivity, val currentUri: S
|
|||
dialog.dismiss()
|
||||
}
|
||||
else -> try {
|
||||
mediaPlayer.stop()
|
||||
mediaPlayer?.reset()
|
||||
if (mediaPlayer == null) {
|
||||
mediaPlayer = MediaPlayer().apply {
|
||||
setAudioStreamType(audioStream)
|
||||
setDataSource(activity, Uri.parse(alarmSound.uri))
|
||||
isLooping = loopAudio
|
||||
}
|
||||
}
|
||||
|
||||
mediaPlayer?.apply {
|
||||
setDataSource(activity, Uri.parse(alarmSound.uri))
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
|
@ -129,6 +135,7 @@ class SelectAlarmSoundDialog(val activity: BaseSimpleActivity, val currentUri: S
|
|||
activity.showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeAlarmSound(alarmSound: AlarmSound) {
|
||||
val token = object : TypeToken<ArrayList<AlarmSound>>() {}.type
|
||||
|
|
Loading…
Reference in a new issue