Open defagos opened 2 years ago
I attempted to solve the issue as follows:
AVAudioSession
configuration methods to emit notifications when the configuration is changed. This is quite fragile as currently each method must separately be swizzled, as there is no common method and convenience methods, rather several separate methods which don't call each other.This sadly does not work. The only way I know of to make the system realize that audio is being heard again after temporarily switching to .mixWithOthers
is to pause and resume the player, what our fellow SRF colleagues who reported the issue already suggested. But this makes the UI appear again, as we cannot know how a rate change is produced (we use KVO).
I also reproduced the issue by tweaking Apple audio session sample, which proves the issue is not related to our implementation. I should report this as a bug to Apple (iOS 16 beta exhibits the same behavior).
In the meantime I quite don't know what to do.
I reported the issue to Apple as FB11416789. Sample code is available as well. Here is the report I made:
Applications might need to toggle AVAudioSession
settings back and forth between .default
and .mixWithOthers
, e.g. when switching back and forth between an immersive full screen playback experience and a feed browsing experience presenting videos playing automatically without sound.
Control center integration availability depends on audio session settings. The .default option is namely required for proper control center metadata and playback control integration. When using .mixWithOthers
control center integration is therefore not expected to be available, and this is what we currently correctly observe. The problem is that, while control center integration is correctly disabled when switching from .default
to .mixWithOthers
, it is incorrectly not enabled in the reverse direction, i.e. when switching from .mixWithOthers
to .default
.
The issue affects recent iOS versions (tested with 15.6.1 and 16 beta 8).
I attached a sample project to this issue. This project implements a simple video playback experience with minimal working control center integration and can be used to reproduce the described issue as follows (you can also see these steps in the attached video):
.playback
category with .default
options..mixWithOthers
audio session option. Open the control center to observe that metadata and playback controls are not available anymore, as expected when using this audio session option..default
. Open the control center to observe that metadata and playback controls are still not available, though you would expect them to be available with this audio session option.It seems that the issue is that iOS incorrectly fails to not detect that "a main playback" user experience is occurring when switching from .mixWithOthers
to .default
. You can test this intuition in the demo:
Assuming proper control center integration has been implemented, switching audio session options from .default
to .mixWithOthers
disables control center integration, while switching from .mixWithOthers
to .default
enables it.
Assuming proper control center integration has been implemented, switching audio session options from .default
to .mixWithOthers
disables control center integration, but switching from .mixWithOthers
to .default
fails to enable it.
When switching the audio session
AVAudioSessionCategoryOptionMixWithOthers
option on, control center integration is automatically disabled by the system. When switching it back to off the control center is not automatically refreshed until the user pauses and resumes playback, e.g.Issue type
Incorrect behavior
Environment information
Reproducibility
Always reproducible
Code sample
In
AdvancedPlayerViewController~ios.m
insert the following implementation to replace the existing one:Steps to reproduce