0

Issue: When the iOS device is on silent, the sound being played from the app is muted.

Upon some digging into the iOS code, I found that out of the 7 "audio session categories" the right one to use for a music app is playback.

Question: How do I set the category in the audio_service package?

Package version: 0.18.0-beta.1

Survy
  • 118
  • 7

2 Answers2

1

audio_service only manages remote control of your app via notifications, lock screens, etc. The audio session is typically managed by the audio player plugin that you use.

If you use just_audio, it will by default set the required category, but if not, you can manually override the category via the audio_session package. e.g. The code below will configure reasonable defaults for a podcast app, including setting the category to playback:

(await AudioSession.instance).configure(const AudioSessionConfiguration.speech());
Ryan Heise
  • 2,273
  • 5
  • 14
  • We already have this code added & it was working fine until few days back but recently it has stopped working, any help would be appreciated! – Wilson Christian Sep 22 '21 at 10:52
  • It is possible that another audio plugin is overriding your own setting. What audio player plugin are you using? – Ryan Heise Sep 23 '21 at 02:50
  • We are using `audio_session`, `just_audio` & `audio_service`. I have tried to set audio category (playback) in `AppDelegate` as well which doesn't work. – Wilson Christian Sep 23 '21 at 05:22
  • What other plugins are you using that might interact with the audio session, and does your app load plugins in multiple isolates? – Ryan Heise Sep 23 '21 at 07:08
  • Thanks for your help! It was in fact one of the other plugins, "hardware_buttons" that was overriding the category. Once we commented that out, it worked fine. (note for future readers - Wilson and I are co-workers so I'm referring to the same project here) – Survy Sep 26 '21 at 17:37
1

This library helped me to solve this problem: https://pub.dev/packages/audio_session

import 'package:audio_session/audio_session.dart';
...
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration.music());
...
Ilya Iksent
  • 1,425
  • 17
  • 15