Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

DerJojo11
Copy link
Contributor

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?

when start listening or reading the volume.

Add the category ambient to allow music to play.
Some Refactorings
@yosemiteyss
Copy link
Owner

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

@yosemiteyss yosemiteyss merged commit c58634b into yosemiteyss:main Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants