-1

I'm a flutter developer and I need help from senior developers. I've a really nice client who wants me to create a mobile app on flutter that includes audio management in a way that I'm not sure how to do it. so, for example if a user is streaming music through spotify, and then he plays something from soundcloud. Spotify will be paused automatically. Here my client wants a feature in the app that if user wants to keep them playing both simultaneously, or if user wants to play local file simultaneously with spotify or any other app. He can manage both these things through app. Is there any way to do this thing through flutter? If no then what are the possible alternatives for this feature. Thanks in advance.

EDIT: I've got a thing in my mind about it. Intents can be useful somehow, can we resume or pause audio in other apps using intents? How can I get the list of apps playing audio in my app?

  • Flutter is primarily for UI. This kind of interaction with the OS will likely require diving into the native APIs. – fdcpp Oct 31 '21 at 10:04
  • @fdcpp Thanks for feedback, Can you please help me finding some APIs or ways to do these? – Hamza Kaleem Nov 02 '21 at 16:54
  • This will be achieved through the native APIs which may have a couple of different points of entry. For iOS I’d look at [AVFoundation](https://developer.apple.com/av-foundation/) and perhaps this SO thread https://stackoverflow.com/questions/28781283/set-avaudioengine-input-and-output-devices#28789462 – fdcpp Nov 07 '21 at 13:57
  • For Android, you need to refer to the Android SDK https://source.android.com/devices/audio/ – fdcpp Nov 07 '21 at 14:01
  • For Web Audio, see https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/selectAudioOutput – fdcpp Nov 07 '21 at 14:02

1 Answers1

0

looks like your client wants to disable some feature of Android OS called audio focus

Two or more Android apps can play audio to the same output stream simultaneously, and the system mixes everything together. While this is technically impressive, it can be very aggravating to a user. To avoid every music app playing at the same time, Android introduces the idea of audio focus. Only one app can hold audio focus at a time.

you can try to avoid this behavior in your own app (playing some audio, when another app is also playing smth), but you simply can't change/disallow respecting audio focus by other apps

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • Thanks for your answer, there's an app called sound assistant created by samsung and it does pretty much the same job. What do you think about it? Thanks again. – Hamza Kaleem Oct 31 '21 at 01:44
  • I do think and even I'm sure that apps developed by Google (Android producer) or device manufacturer (e.g. Samsung) have special privileges as these are system apps (installed on system partition, signed with proper key, not-uninstallable in fact). "usual" apps won't get such perms/possibilities – snachmsm Nov 01 '21 at 09:41