[iOS17] AVPlayer+AudioTapProcessor fails on Apple Clock's alarm notification

Hello all,

I've been developing a video player app using AVPlayer with AudioTapProcessor. Where AudioTapProcessor is used to render audio data with the custom filters.

Recently, I've updated my iPhone to the newest iOS 17 and noticed an unusual behavior on system alarm triggered by the Apple Clock app.

Is there a change in iOS 17 that could perhaps cause this issue? If not, does anyone have any idea where I should look into?


Steps to Reproduce:

  1. Turn off Slient/Vibration Mode on the device
  2. Play AVPlayer (w/ AudioTapProcessor)
  3. Set Alarm/Timer on the Apple Clock app (set Sound other than "None")

Result (Unusual Behavior):

  • Alarm triggered without any sound
  • AVPlayer sound stops
    • Output log: rt_receiver::receive_loop failed: 89
  • AVPlayerItem.failedToPlayToEndTimeNotification gets triggered from NotificationCenter

More Info:

  • Only way to bypass (for now) is to re-initiate AVPlayer instance after AVPlayerItem.failedToPlayToEndTimeNotification
  • Issue doesn't happen:
    • on iOS 16.3.1 device
    • when alarm happens before loading AVPlayer
    • when AudioTapProcessor is detached from AVPlayer
    • when alarm triggers from apps other than the Apple Clock
  • Manually pause()/play() on AVAudioSession.interruptionNotification handler doesn't help
  • Running AddressSanitizer results in "Deallocation of non-allocated memory" in libclang_rt.dylib

@peurocs4 I have been facing a similar issue. I think there is an extra retain somewhere in AVPlayer, or a race condition, that is causing the audio tap to be held onto, or not fully removed when the player is deallocated. My temporary solution has been to set the audio mix to nil when the View Controller that holds on to it is dealloced.

I'm working on creating an Xcode scenario for Apple to debug this. Let me know if you have something that could possibly help here too. Without an Xcode project we won't get much traction from Apple.

I'm experiencing a similar problem, but with a different situation. Everything used to work perfectly fine from iOS 9.0 up until iOS 17. In my case, I'm using two AVPlayer instances to create a crossfade effect. To achieve this, I use an audio mix and the "setVolumeRampFromStartVolume:toEndVolume:timeRange:" method to create a fade-out for the current track and a fade-in effect for the next track. Now, when there are 5 seconds left until the current track ends, I start the next AVPlayer, and during the crossfade transition, both players play simultaneously. This setup worked flawlessly on iOS 17.0, 17.1, iOS 17.2.

However, things take a turn when you add MTAudioProcessingTapCallbacks to the audio mix (to implement 10-band equalizer in my case). After assigning the audioTapProcessor to the audio mix of both the current and next player items and attempt to start the next player before the current player has finished (to create the crossfade effect), you'll start hearing a sound crackling issue.

In the Xcode console, you'll likely see the "rt_receiver::receive_loop failed: 89" error.

You can reproduce this issue after playing 2-3 tracks. If you're using AVQueuePlayer in combination with MTAudioProcessingTapCallbacks, everything goes smoothly on iOS 17. However, if you opt for two separate AVPlayers, both with an audio mix that has MTAudioProcessingTapCallbacks, you'll consistently run into this issue across iOS 17.0, 17.1, and 17.2.

[iOS17] AVPlayer+AudioTapProcessor fails on Apple Clock's alarm notification
 
 
Q