Skip to content

Commit c496636

Browse files
committed
* Added backup beep sound if for some reason users can't play alarm sounds due to permission issues.
1 parent 8982b2d commit c496636

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/views/BaseAlarmView.kt

+14-2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ abstract class BaseAlarmView : LinearLayout {
206206
if(!useSystemSound)
207207
return
208208

209+
if (soundUtils != null) {
210+
soundUtils?.destroyBuzzer()
211+
}
212+
209213
if(mediaPlayer != null) {
210214
mediaPlayer?.stop()
211215
}
@@ -226,9 +230,17 @@ abstract class BaseAlarmView : LinearLayout {
226230
mediaPlayer = MediaPlayer.create(context!!, alert)
227231
mediaPlayer?.start()
228232
} catch (e: SecurityException) {
229-
Timber.e(e.message)
233+
playContinuousBeep()
230234
} catch(e: FileNotFoundException) {
231-
Timber.e(e.message)
235+
playContinuousBeep()
236+
}
237+
}
238+
239+
private fun playContinuousBeep() {
240+
if (soundUtils == null) {
241+
soundUtils = SoundUtils(context)
242+
soundUtils?.init()
243+
soundUtils?.playBuzzerRepeat()
232244
}
233245
}
234246

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/utils/SoundUtils.kt

-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ class SoundUtils(base: Context) : ContextWrapper(base) {
3131
stopBuzzerRepeat()
3232
}
3333

34-
fun playBuzzerOnButtonPress() {
35-
Timber.d("playBuzzerOnButtonPress")
36-
if (repeating) {
37-
stopBuzzerRepeat()
38-
repeating = false
39-
}
40-
soundHandler?.post(streamAudioRunnable);
41-
}
42-
4334
private val streamAudioRunnable = Runnable {
4435
val speaker = MediaPlayer.create(applicationContext, R.raw.beep)
4536
speaker.setOnCompletionListener { mp ->

0 commit comments

Comments
 (0)