Skip to content
FengYan枫炎 edited this page Aug 23, 2025 · 1 revision

Audio

AVAudioSession音频相关API。

事件

event Action<AVAudioSessionInterruptionType> AudioInterruptionEvent

游戏音频中断与恢复事件。

event Action AudioSessionRouteChangedEvent

玩家音频设备变更事件。

方法

bool SetActive(bool active)

设置AVAudioSession的激活状态 。

  • 返回值:是否成功抢占音频优先权

bool PrefersNoInterruptionsFromSystemAlerts

设置系统铃声时是否中断Audio Session。

Beginning in iOS 14, users can set a global preference that indicates whether the system displays incoming calls using a banner or a > full-screen display style. If using the banner style, setting this value to true prevents the system from interrupting the audio session with incoming call notifications, and gives the user an opportunity to accept or decline the call. The system only interrupts the audio session if the user accepts the call.

Enabling this preference can improve the user experience of apps with audio sessions that you don’t want to interrupt, such as those that record audiovisual media or that you use for music performance.

This preference has no effect if the device uses the full-screen display style—the system interrupts the audio session on incoming calls.

bool AudioInterrupted

当前AudioSession是否被中断(游戏处于后台时无法更新状态,可能导致结果不准确)。

float SystemVolume()

当前系统音量。

https://developer.apple.com/documentation/avfaudio/avaudiosession/1616533-outputvolume?language=objc

  • 返回值:音量(0-1)

double InputLatency()

音频输入延迟。

  • 返回值:延迟(秒)

double OutputLatency()

音频输出延迟。

  • 返回值:延迟(秒)

double SampleRate()

音频采样率。

  • 返回值:采样率(Hertz)

bool IsBluetoothHeadphonesConnected()

判断玩家当前是否连接了蓝牙耳机。

void SetAudioExclusive(bool exclusive)

调用此方法可静音/暂停设备后台正在播放的音频。

Clone this wiki locally