Categories: Uncategorized

Tips for Managing AVAudioSession API and Issues with AirPods

During audio development on our iOS application, the team at Red5 Pro found that Apple’s AirPods cause rendering issues while subscribing to a stream after they have been successfully paired with a device. As it turns out, there are a few limitations to Apple’s Bluetooth headsets which alter the stream in unexpected ways. The good news is that if you are facing AV sync or other microphone issues when using AirPods with your iOS application, we may have a solution to your problem.

Red5 Pro has several mobile testbed examples that demonstrate how to maintain the audio from a stream while the mobile app is in the background. In the iOS examples, the app listens for events in the Notification Center to recognize when the app goes to the background. Specifically, it listens for the UIApplication.willResignActiveNotification and pauses video rendering upon finding it. This worked well for a variety of scenarios, including alerts of incoming phone calls or the user hitting the home button while the stream is active. Recently, however, we saw an issue related to the notification presented while pairing AirPods to the device.

When AirPods pair with a device, they present an alert that causes the currently-open application to move to the background briefly. In our iOS testbed, the background tests behaved as expected; they paused rendering and maintained audio streaming while the AirPods pairing notification was present on the screen. However, once the notification is gone, the app listens for a specific UIApplication.willEnterForegroundNotification event, and with AirPods this event was never invoked. Instead, the app attempts to move directly to a different event,  UIApplication.didBecomeActiveNotification, without first switching the app back to the foreground. We noticed that the application stopped using the AVAudioSession defined for our SDK because the callback assigned to process audio frames stopped being called once the AirPods had successfully connected and resumed being called if they were disconnected.

Finding a Solution for the AirPod Pairing Issue While Streaming

After some research, it became clear that the main issue with the AirPods we tested is that they do not support audio sessions with the PlayAndRecord category, which is what our subscriber audio session used. Due to this limitation, when an audio session becomes active, the device takes over the current audio session and replaces it with one that the AirPods support. This audio takeover defaults to a frame size of 1156, which is too small for our application, therefore causing an exception and pausing playback.

We found that overriding the audio takeover and setting the category of the subscriber audio session to Playback instead of PlayAndRecord fixes the problem, so that the session works as expected with a sample rate of 44100. This allows audio to switch to the headphones when they are connected and back to speakers when disconnected, while continuing to render the stream. Note that this is specific to Apple’s Bluetooth headsets and was not seen with other Bluetooth headsets that we tested.


If you’re running into AV sync issues during iOS development, this might be the solution for you. Let us know if we were able to help by joining our Slack community or contacting us at info@red5.net.

Red5 Team

Share
Published by
Red5 Team

Recent Posts

Red5 on OCI vs AWS IVS: Why Oracle Cloud Infrastructure is an Excellent Choice for Live Streaming

As organizations evaluate live streaming solutions, Amazon Interactive Video Service (IVS) has emerged as a…

5 days ago

What’s New in Red5 Cloud v1.9.2? Valuable UI/UX Improvements and Bug Fixes

Let’s go over the latest updates introduced in Red5 Cloud since our previous blog covering…

6 days ago

Real-Time Streaming Solutions for 2025: Red5 vs. Phenix vs. Dolby Optiview

When businesses need ultra-low latency streaming capabilities, the choice of platform can significantly influence the…

2 weeks ago

AWS IVS vs Red5: Choosing the Right Live Streaming Solution for Your Business

1Understanding AWS IVS: Strengths and Limitations2Red5: A More Flexible Alternative3When to Choose Red5 Over AWS…

4 weeks ago

What’s New in Red5 Pro v14.2.1 and Red5 Cloud v1.9.1?

Let’s take a look at the latest Red5 Pro and Red5 Cloud releases introduced since…

1 month ago

AV1 vs VP9 vs. VP8: Complete Codec Evolution and Comparison for Live Streaming

1Quick Comparison Overview2The Complete Evolution: VP8 → VP9 → AV13Technical Comparison: VP8 vs VP9 vs…

1 month ago