diff --git a/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt b/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt index 047cb18..7b001d2 100644 --- a/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt +++ b/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt @@ -94,7 +94,6 @@ object SleepNotification { muteMediaIntent.action = BROADCAST_ACTION_MUTE val pendingMuteIntent = PendingIntent.getBroadcast(this, 0, muteMediaIntent, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) - val notification = Notification.Builder(this, CHANNEL_ID_SLEEPTIMER) .setCategory(Notification.CATEGORY_EVENT) .setVisibility(Notification.VISIBILITY_PUBLIC) diff --git a/app/src/main/java/com/maary/liveinpeace/receiver/MuteMediaReceiver.kt b/app/src/main/java/com/maary/liveinpeace/receiver/MuteMediaReceiver.kt index d80cb32..c13842f 100644 --- a/app/src/main/java/com/maary/liveinpeace/receiver/MuteMediaReceiver.kt +++ b/app/src/main/java/com/maary/liveinpeace/receiver/MuteMediaReceiver.kt @@ -3,7 +3,12 @@ package com.maary.liveinpeace.receiver import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.media.AudioAttributes +import android.media.AudioAttributes.CONTENT_TYPE_MUSIC +import android.media.AudioAttributes.USAGE_MEDIA +import android.media.AudioFocusRequest import android.media.AudioManager +import android.media.AudioManager.AUDIOFOCUS_GAIN import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_MUTE import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_SLEEPTIMER_CANCEL import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_SLEEPTIMER_DECREMENT @@ -20,6 +25,10 @@ class MuteMediaReceiver: BroadcastReceiver() { do { audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0) } while (audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) > 0) + + val attributes = AudioAttributes.Builder().setUsage(USAGE_MEDIA).setContentType(CONTENT_TYPE_MUSIC).build() + val focusRequest = AudioFocusRequest.Builder(AUDIOFOCUS_GAIN).setAudioAttributes(attributes).setOnAudioFocusChangeListener {}.build() + audioManager.requestAudioFocus(focusRequest) } if (p1?.action == BROADCAST_ACTION_SLEEPTIMER_CANCEL ||