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).

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.

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.