audiosession

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Hold

func Hold(level Level) (release func(), err error)

Hold sets the session to level, or keeps the higher one held, until release, which does nothing called again. When the session cannot be set and activated, Hold holds nothing and returns why.

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL