mediaPlayer audio fades in when I set when AudioAttributes.USAGE_ALARM


I have an app that runs a mediaPlayer.
I need it to to play some media upon receiving android.intent.action.BOOT_COMPLETED, so I had to change AudioAttributes.USAGE_MEDIA to AudioAttributes.USAGE_ALARM, as per some API 37 developer notes

private val audioAttributes: AudioAttributes = AudioAttributes.Builder()
        .setUsage(AudioAttributes.USAGE_ALARM)
        .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
        .build()
mediaPlayer = MediaPlayer.create(this, R.raw.example, audioAttributes, audioManager.generateAudioSessionId())

The problem is that the app will now fade the media volume up from 0%, for the firs 2-2.5 seconds, and I don't want that to happen.

Here is a video of the issue, on google photos.

Any suggestions? Thank you in advance.

EDIT:

I am very certain that this fade-in effect is a direct result of setting USAGE_ALARM, as I have previously switched back and forth between the two.

0
Nov 19 at 8:54 PM
User AvatarProject Awesome
#android#android-mediaplayer

No answer found for this question yet.