yosemiteyss / flutter_volume_controller

A Flutter plugin to control system volume and listen for volume changes on different platforms.
https://pub.dev/packages/flutter_volume_controller
MIT License
16 stars 10 forks source link

Fix the bug, that the music will pause on iOS #32

Closed DerJojo11 closed 1 year ago

DerJojo11 commented 1 year ago

I found a bug, that the music stops playing as soon you start listen or read the volume. This happens because the default category don't allow to mix music with other apps. Now, when for example Spotify is playing the music will not stop playing on both events.

That's why I added the Category ambient to the AVAudioSession. Also, to have only one instance, I provide the session to both models.

For reading: https://developer.apple.com/documentation/avfaudio/avaudiosessioncategory

Ambient:

The category for an app in which sound playback is nonprimary — that is, your app also works with the sound turned

 private static var audioSession: AVAudioSession {
        let session = AVAudioSession.sharedInstance()
        do {
            try? session.setCategory(AVAudioSession.Category.ambient)
        }
        return session
    }

Maybe, for a better use case : enable to set the options from Flutter?

yosemiteyss commented 1 year ago

Thanks! I will consider adding category control on future version.