|
|
|
@ -99,6 +99,7 @@ public class MediaPlayerHelper {
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
MediaPlayer mediaPlayer = new MediaPlayer();
|
|
|
|
|
try {
|
|
|
|
|
mediaPlayer.setAudioAttributes(attrs);
|
|
|
|
|
mediaPlayer.setDataSource(context.getApplicationContext(), uri);
|
|
|
|
|
mediaPlayer.setLooping(false);
|
|
|
|
@ -117,6 +118,7 @@ public class MediaPlayerHelper {
|
|
|
|
|
mediaPlayer.prepareAsync();
|
|
|
|
|
|
|
|
|
|
NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
|
|
|
|
|
try {
|
|
|
|
|
if (alarm) {
|
|
|
|
|
Intent intent = new Intent(context, ServiceUI.class)
|
|
|
|
|
.setAction("alarm");
|
|
|
|
@ -147,17 +149,18 @@ public class MediaPlayerHelper {
|
|
|
|
|
nm.notify("alarm", 1, builder.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
boolean acquired = sem.tryAcquire(duration, TimeUnit.SECONDS);
|
|
|
|
|
EntityLog.log(context, "Alarm acquired=" + acquired);
|
|
|
|
|
mediaPlayer.stop();
|
|
|
|
|
mediaPlayer.release();
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
} finally {
|
|
|
|
|
if (alarm)
|
|
|
|
|
nm.cancel("alarm", 1);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
mediaPlayer.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.i("Played sound=" + uri);
|
|
|
|
|
|
|
|
|
|