Documentation
¶
Overview ¶
Package audiosession holds iOS's one AVAudioSession for every part of NSGo that sets it: videos, the audio package's players and sounds, speech and microphone. Each holder asks for a level, and the highest held sets the session; once none is held it goes back to the category from before the first and is deactivated, telling other apps they may play. It imports nothing of the module, so microphone and the backends both import it, and guards its holders with a mutex, so the main thread, audio workers and microphone's caller may all call it. Outside iOS it holds nothing.
Deactivating waits for the system, the more so while a player's output still runs down, which an AVPlayer's does for a while after its pause: called on the main thread at once it blocked an iPhone's for about 600 ms at every pause. So the last release only arranges the deactivation, which runs deactivateAfter later on a goroutine of its own, and a hold that comes first keeps the session active instead, at no cost when its level is the one the session has. A hold that comes while the deactivation runs waits for it, then activates the session again.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Level ¶
type Level uint8
Level is what a holder needs of the session, from Kept to Dictation; a higher one wins.
const ( // Kept is a video playing with the default session: the category from before the first holder, the app's own, kept active, so that the session is not deactivated under the playing video, which would stop it. Kept Level = iota + 1 // Ambient is every sound and a player with the default session: the Ambient category, which mixes with other apps' audio and which the Ring/Silent switch and the screen lock silence. Ambient // Mixing is a video or a player with AudioSessionMixWithOthers: Playback in the SpokenAudio mode, mixing with other apps' audio. Mixing // Playback is a video or a player with AudioSessionPlayback: Playback in the SpokenAudio mode, pausing other apps' audio. Playback // Recording is a recording, microphone.Capture: PlayAndRecord with AllowBluetoothHFP and DefaultToSpeaker in the Default mode, which the other levels' sounds play through and the Ring/Silent switch does not silence. Recording // Dictation is a speech session listening: Recording in the Measurement mode. Dictation )