0

In my app, I only want to play a sound when the device ringer is on. Currently the code I have works, but there is a delay for retrieving the device's current ringer status. I am using the audioplayers and sound_mode packages to do this.

  _playSound(String sound) async {
       String ringerStatus = await SoundMode.ringerModeStatus;
       if (ringerStatus.contains("Normal Mode")) {
            return await player.play(sound);
       }
  }

Edit: The problem is that in iOS you have to read the ringer status twice per the sound_mode package documentation.

Sbean
  • 21
  • 2

1 Answers1

0

You can use this package

From the docs , you can do

await SoundMode.ringerModeStatus;
Nikhil Badyal
  • 1,589
  • 1
  • 9
  • 20
  • This is what I’m using, however there is a delay when I change my ringer midway through the app running and it does not reflect the current ringer status in time. For example, when I set my ringer from normal to silent, it will not reflect the change on the first iteration of the _playSound() function, but it will on the next iteration. – Sbean Apr 19 '21 at 17:01