Skip to content

Commit

Permalink
ao_audiounit: use non-exclusive audio session
Browse files Browse the repository at this point in the history
Using this option means the OS won't pause other
sources of audio when playback starts in MPV.

But if --audio-exclusive is used, still use an exclusive session.

This should apply to iOS, iPadOS, and tvOS.
  • Loading branch information
moffatman committed Dec 22, 2024
1 parent 7768c3d commit 4d7ef4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1900,8 +1900,8 @@ Audio
Enable exclusive output mode. In this mode, the system is usually locked
out, and only mpv will be able to output audio.

This only works for some audio outputs, such as ``wasapi``, ``coreaudio``
and ``pipewire``. Other audio outputs silently ignore this option.
This only works for some audio outputs, such as ``wasapi``, ``coreaudio``,
``pipewire`` and ``audiounit``. Other audio outputs silently ignore this option.
They either have no concept of exclusive mode, or the mpv side of the
implementation is missing.

Expand Down
7 changes: 6 additions & 1 deletion audio/out/ao_audiounit.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ static bool init_audiounit(struct ao *ao)

MP_VERBOSE(ao, "max channels: %ld, requested: %d\n", maxChannels, (int)ao->channels.num);

[instance setCategory:AVAudioSessionCategoryPlayback error:nil];
AVAudioSessionCategoryOptions options = 0;
if (!(ao->init_flags & AO_INIT_EXCLUSIVE)) {
options |= AVAudioSessionCategoryOptionMixWithOthers;
}

[instance setCategory:AVAudioSessionCategoryPlayback withOptions:options error:nil];
[instance setMode:AVAudioSessionModeMoviePlayback error:nil];
[instance setActive:YES error:nil];
[instance setPreferredOutputNumberOfChannels:prefChannels error:nil];
Expand Down

0 comments on commit 4d7ef4f

Please sign in to comment.