File tree 2 files changed +14
-11
lines changed
app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel
2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,10 @@ abstract class BaseAlarmView : LinearLayout {
206
206
if (! useSystemSound)
207
207
return
208
208
209
+ if (soundUtils != null ) {
210
+ soundUtils?.destroyBuzzer()
211
+ }
212
+
209
213
if (mediaPlayer != null ) {
210
214
mediaPlayer?.stop()
211
215
}
@@ -226,9 +230,17 @@ abstract class BaseAlarmView : LinearLayout {
226
230
mediaPlayer = MediaPlayer .create(context!! , alert)
227
231
mediaPlayer?.start()
228
232
} catch (e: SecurityException ) {
229
- Timber .e(e.message )
233
+ playContinuousBeep( )
230
234
} 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()
232
244
}
233
245
}
234
246
Original file line number Diff line number Diff line change @@ -31,15 +31,6 @@ class SoundUtils(base: Context) : ContextWrapper(base) {
31
31
stopBuzzerRepeat()
32
32
}
33
33
34
- fun playBuzzerOnButtonPress () {
35
- Timber .d(" playBuzzerOnButtonPress" )
36
- if (repeating) {
37
- stopBuzzerRepeat()
38
- repeating = false
39
- }
40
- soundHandler?.post(streamAudioRunnable);
41
- }
42
-
43
34
private val streamAudioRunnable = Runnable {
44
35
val speaker = MediaPlayer .create(applicationContext, R .raw.beep)
45
36
speaker.setOnCompletionListener { mp ->
You can’t perform that action at this time.
0 commit comments