Revert "Stop alarm on screen on/off"

This reverts commit c49d83b3eb.
pull/213/head
M66B 1 year ago
parent c49d83b3eb
commit db496e7254

@ -1,10 +1,7 @@
package eu.faircode.email;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
@ -52,8 +49,6 @@ public class MediaPlayerHelper {
private static void play(Context context, Uri uri, boolean alarm, int duration) throws IOException {
Semaphore sem = new Semaphore(0);
Log.i("Play uri=" + uri);
AudioAttributes attrs = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(alarm ? AudioAttributes.USAGE_ALARM : AudioAttributes.USAGE_NOTIFICATION)
@ -79,35 +74,15 @@ public class MediaPlayerHelper {
});
mediaPlayer.prepareAsync();
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("Received " + intent);
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF) ||
intent.getAction().equals(Intent.ACTION_SCREEN_ON))
sem.release();
}
};
try {
IntentFilter iff = new IntentFilter();
iff.addAction(Intent.ACTION_SCREEN_OFF);
iff.addAction(Intent.ACTION_SCREEN_ON);
context.registerReceiver(receiver, iff);
try {
boolean acquired = sem.tryAcquire(duration, TimeUnit.SECONDS);
EntityLog.log(context, "Alarm acquired=" + acquired +
" playing=" + mediaPlayer.isPlaying());
if (!acquired || mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();
}
} catch (Throwable ex) {
Log.w(ex);
boolean acquired = sem.tryAcquire(duration, TimeUnit.SECONDS);
EntityLog.log(context, "Alarm acquired=" + acquired);
if (!acquired) {
mediaPlayer.stop();
mediaPlayer.release();
}
} finally {
context.unregisterReceiver(receiver);
} catch (Throwable ex) {
Log.w(ex);
}
}

Loading…
Cancel
Save