AudioSession Policies

The StreamVideo SDK provides a flexible mechanism for configuring audio sessions through its AudioSessionPolicy protocol. These policies govern how the app configures the audio session category and mode, taking into account user capabilities or app-specific requirements.

By attaching an AudioSessionPolicy to your call, you can standardize how audio input (microphone) and output (speaker/headphones) are managed in different scenarios.

Built-In Policies

DefaultAudioSessionPolicy

Use this for straightforward call scenarios where the user can send and receive audio without complex restrictions. Typically:

  • Category: .playAndRecord when audio is on.
  • Mode: .videoChat (or .voiceChat depending on the CallSettings.speakerOn value).
  • Options: .allowBluetooth, allowBluetoothA2DP and .allowAirPlay.

This lets participants communicate freely, using the microphone and speaker/headphones.

Example usage

let call = streamVideo.call(callType: "default", callId: "chat-123")
let policy = DefaultAudioSessionPolicy()

Task {
    try await call.updateAudioSessionPolicy(policy)
}

OwnCapabilitiesAudioSessionPolicy

Targets situations where different participants have different permissions. For instance, if a user cannot send audio (no .sendAudio capability), the policy will set .playback category (receiving audio only). Otherwise, it transitions between .playback and .playAndRecord depending on user’s state (e.g., whether they’ve toggled microphone or speaker on).

Example usage

let call = streamVideo.call(callType: "default", callId: "team-meet")
let policy = OwnCapabilitiesAudioSessionPolicy()

Task {
    try await call.updateAudioSessionPolicy(policy)
}

This is useful if you need dynamic restrictions based on your business logic (e.g., Livestream viewers, paying customers can speak, free-tier can only listen).

LivestreamAudioSessionPolicy

This policy is intended to be used for livestreams where audio quality matters the most. It supports stereo playout across various audio source outputs including device’s speaker and supported external devices (e.g. bluetooth or wired headsets).

The policy uses .playback category, .default mode and .allowBluetoothA2DP category options.

Example usage

let call = streamVideo.call(callType: "default", callId: "team-meet")
let policy = LivestreamAudioSessionPolicy()

Task {
    try await call.updateAudioSessionPolicy(policy)
}

This policy only supports participants that don’t have microphone permissions. That’s due to a WebRTC limitation and the underline AVAudioUnit implementation/usage. When the microphone activates, AVAudioUnit gets configured for mono ouput in order to support microphone input. Muting the microphone again won’t restore stereo playout. The only way to restore stereo playout is to leave and join the call again.

When to Use Each Policy

  • DefaultAudioSessionPolicy: Ideal for general-purpose calls where everyone is allowed to speak.
  • OwnCapabilitiesAudioSessionPolicy: Useful for dynamically restricting or enabling send-audio privileges based on user roles or subscription tiers.
  • LivestreamAudioSessionPolicy: Ideal for Livestreams where the participant doesn’t have (and won’t be granted) the sendAudio capability.

Conclusion

By selecting an appropriate AudioSessionPolicy, you easily manage how your app handles input and output audio. This integration reduces boilerplate and keeps audio logic centralized, ensuring consistent experiences across various call types and user roles.

© Getstream.io, Inc. All Rights Reserved.