ryanheise / audio_session

MIT License
107 stars 68 forks source link

AudioSessionConfiguration with multiple categories causes PlatformException(-50) #127

Open thedeukalion opened 3 months ago

thedeukalion commented 3 months ago

With this configuration:

const AudioSessionConfiguration(
      avAudioSessionCategory: AVAudioSessionCategory.playback,
      avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.mixWithOthers
        | AVAudioSessionCategoryOptions.allowBluetoothA2dp 
        | AVAudioSessionCategoryOptions.allowBluetooth,
      avAudioSessionMode: AVAudioSessionMode.defaultMode,
      avAudioSessionRouteSharingPolicy: AVAudioSessionRouteSharingPolicy.defaultPolicy,
      avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
      androidAudioAttributes: AndroidAudioAttributes(
        contentType: AndroidAudioContentType.sonification,
        flags: AndroidAudioFlags.none,
        usage: AndroidAudioUsage.media,
      ),
      androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
      androidWillPauseWhenDucked: false,
)

Will cause error: PlatformException(-50, The operation couldn’t be completed)

And here is obvious support for flags in AVAudioSessionCategoryOptions: https://github.com/ryanheise/audio_session/blob/master/lib/src/darwin.dart#L370

And the native code that this probably relates to: https://developer.apple.com/documentation/avfaudio/avaudiosession/1771734-setcategory (A mask of additional options for handling audio. For a list of constants, see AVAudioSession.CategoryOptions.)

Either the documentation is not good enough or how can this be a misconfiguration and why is this throwing errors?

Removing the bluetooth configuration makes the configuration work.