Skip to content

fix(ios)!: use AVAudioSessionCategory.playAndRecord as default#1501

Closed
wujek-srujek wants to merge 3 commits into
bluefireteam:mainfrom
wujek-srujek:fix/1491-ios-ducking-crash
Closed

fix(ios)!: use AVAudioSessionCategory.playAndRecord as default#1501
wujek-srujek wants to merge 3 commits into
bluefireteam:mainfrom
wujek-srujek:fix/1491-ios-ducking-crash

Conversation

@wujek-srujek

@wujek-srujek wujek-srujek commented May 8, 2023

Copy link
Copy Markdown
Contributor

Description

Now if ducking is requested, iOS doesn't crash. Also, the default instance of AudioContextIOS in Dart corresponds to the one in Swift, making the feature consistent.

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs:, chore: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation and added dartdoc comments with ///, where necessary.
  • I have updated/added relevant examples in example.

Breaking Change

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

Yes, it is a breaking change because it changes the default value for the audio category on iOS if the user doesn't specify it explicitly when creating a new AudioContextIOS.

Migration instructions

If the user wants the category to be playback, they need to set it explicitly.

Before:

final context = AudioContextIOS();

After:

final context = AudioContextIOS(
  category: AVAudioSessionCategory.playback,
);

Related Issues

Closes #1491

BREAKING CHANGE: `AudioContextIOS.category` default value changes.
@Gustl22

Gustl22 commented May 14, 2023

Copy link
Copy Markdown
Collaborator

Thanks. If breaking I would want to wait for the next major release and also ensure, if we could make playback the default.

Until then this config should fulfill your needs:

AudioContextIOS(
    category: AVAudioSessionCategory.playAndRecord,
    options: [
        AVAudioSessionOptions.mixWithOthers,
        AVAudioSessionOptions.duckOthers,
    ],
)

@Gustl22 Gustl22 changed the title feat!: Fix crash on iOS when ducking is requested (#1491) fix(ios)!: use AVAudioSessionCategory.playAndRecord as default Jun 12, 2023
@Gustl22

Gustl22 commented Jun 12, 2023

Copy link
Copy Markdown
Collaborator

I think it's fine to use the playAndRecord as default, makes the library a bit more expectable. Can't test it though ;D

Gustl22
Gustl22 previously approved these changes Jun 12, 2023
@Gustl22 Gustl22 self-requested a review June 12, 2023 17:58
@Gustl22

Gustl22 commented Jun 12, 2023

Copy link
Copy Markdown
Collaborator

@wujek-srujek can you validate if you can play the sound through the headphones, if using playAndRecord as default?
See: #1486 (comment)
Otherwise it would be a good reason to use playback as not being able to play through a headset is not expected to happen.

@wujek-srujek

Copy link
Copy Markdown
Contributor Author

Unfortunately I won't be able to do it for about 3 more weeks due to vacation and very limited connectivity (and no computer), but will get to it afterwards.

@Gustl22 Gustl22 dismissed their stale review June 26, 2023 07:48

Discussion in #1486 shows that this is probably not the right default value.

@Gustl22

Gustl22 commented Jun 26, 2023

Copy link
Copy Markdown
Collaborator

As stated here (#1545 (comment)) earpeace only is equal to playAndRecord. So switching to playback as default would allow BT headphones, while also let the sound coming from speakers by default.

Gustl22 added a commit that referenced this pull request Jul 6, 2023
# Description

Supersedes #1501

* Introduce `AudioContextConfigRoute` to allow forcing audio to
`speaker` or `earpiece` (this can be extended to e.g. bluetooth devices)
for both iOS and Android
* ios: change default AVAudioSessionCategory from `.playAndRecord` to
`.playback` to not play from earpiece as in record mode (see #1194)
* ios: remove default `AVAudioSessionOptions.defaultToSpeaker` to allow
playing from system default device instead of speaker only (see #1486)
* android: change default AudioContextAndroid.isSpeakerphoneOn from
`true` to `false` to allow playing from system default device instead of
speaker only (see #1486)
* ios: remove default `AVAudioSessionOptions.mixWithOthers` to interrupt
audio of other apps, like in Android
* android: change default AudioContextAndroid.stayAwake from `true` to
`false` to not stay awake, like in iOS

## Breaking Change

### Migration instructions

|Before|After|
|---|---|
|`AudioContextAndroid()`|`AudioContextAndroid(isSpeakerphoneOn: true,
stayAwake: true)`|
|`AudioContextIOS()`|`AudioContextIOS(category:
AVAudioSessionCategory.playAndRecord, options:
[AVAudioSessionOptions.mixWithOthers,
AVAudioSessionOptions.defaultToSpeaker])`|
|`AudioContextConfig()`|`AudioContextConfig(route:
AudioContextConfigRoute.speaker, stayAwake: true})`|


## Related Issues

Closes #1491
Closes #1486
#1194
@Gustl22

Gustl22 commented Jul 6, 2023

Copy link
Copy Markdown
Collaborator

This should now be solved in #1563. We would be glad if you could verify. Feel free to reopen, if the issue isn't solved.

@Gustl22 Gustl22 closed this Jul 6, 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.

iOS crash when setting duck

2 participants