App Freezes with AVPlayer Inside NavigationStack on iOS 17.2 beta

I've encountered a critical issue while testing my app, which is available on the App Store, on the iOS 17.2 beta (iPhone SE simulator). The app freezes and becomes unresponsive. Currently, I haven't found a workaround, which means my app is completely non-functional and untestable on iOS 17.2 beta.

The app supports iOS 15.2 and later versions, and it has been working fine from iOS 15.2 through iOS 17.1. The problem only occurs on the iOS 17.2 beta.

I have been able to reproduce the issue with the sample code provided below.

■ Test Environment:

  • macOS: 14.0 (23A344)
  • Xcode Version: 15.1 beta (15C5042i)
  • iPhone SE 3rd generation (simulator): iOS 17.2 (21C5029e)

■ Steps to Reproduce:

Prerequisites: Prepare an audio file, such as an m4a or mp3, and add it to the Bundle Resources.

1 Launch the sample code provided below.

2 Tap on any row's NavigationLink.

After tapping, when the program attempts to access the AVPlayer, the following log is displayed in Xcode:

  CA_UISoundClient.cpp:1127  Device = 0
  HALPlugInManagement.cpp:396    HALPlugInManagement::RegisterPlugIns: loading in-process plug-ins
AddInstanceForFactory: No factory registered for id <CFUUID 0x600000285600> F8BB1C28-BAE8-11D6-9C31-00039315CD46
     CA_UISoundClient.cpp:1203  renderer = 0x600000011f90, synchronizer: 0x0, repeat: 0, vol: 1.00

3 Tap the Navigation's Back button at the top left.

Depending on the timing, there may be no response when pressing the button (screen). Approximately 15 seconds later, the following log is displayed, and the screen becomes responsive again as it returns to the previous view.

AQMEIO.cpp:198   timed out after 15.000s (0 0); suspension count=0 (IOSuspensions: )
 MEDeviceStreamClient.cpp:467   AQME Default-InputOutput: client stopping after failed start: <CA_UISoundClientBase@0x104015d00>; running count now 0
     CA_UISoundClient.cpp:293   CA_UISoundClientBase::StartPlaying: AddRunningClient failed (status = -66681).
changing items while animating can result in a corrupted navigation bar

4 If the issue does not reproduce, quit the app and then return to step 1.

In the sample code, whether the issue occurs or not may depend on the timing of screen transitions, scrolling, and tapping. (The issue might occur with a high probability if you tap 'back' during a screen transition animation.) On the production app in question, the issue occurs 100% of the time.

■ Sample code


import SwiftUI
import AVFoundation

@main
struct iOSAppHangSampleApp: App {
    
    @StateObject var model = ContentModel()
    
    var body: some Scene {
        WindowGroup {
            if #available(iOS 17, *) {
                NavigationStack {
                    ContentView()
                        .environmentObject(model)
                }
            } else {
                NavigationView {
                    ContentViewIOS15()
                        .environmentObject(model)
                }.navigationViewStyle(.stack)
            }
        }
    }    
}

@MainActor
class ContentModel: ObservableObject {
    private let player = AVPlayer()
    @Published var playbackDuration: TimeInterval = .zero
    
    func load() {
        let url = Bundle.main.url(forResource: "YourAudioFilename", withExtension: "m4a")! // Change to your audio.
        let avassetURL = AVURLAsset(url: url, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
        let avPlayerItem = AVPlayerItem(asset: avassetURL)
        self.player.replaceCurrentItem(with: avPlayerItem)
        self.playbackDuration = avPlayerItem.asset.duration.seconds
    }
}

@available(iOS 17, *)
struct ContentView: View {
    @EnvironmentObject private var model: ContentModel
    
    private let urls: [URL] = {
        (0..<50).map { URL(fileURLWithPath: "\($0)")}
    }()
    
    @State private var selected: Int?
    
    var body: some View {
        List(selection: $selected) {
            ForEach(urls.indices, id: \.self) { idx in
                let _ = urls[idx]
                NavigationLink(value: idx) {
                    Text("\(idx)")
                }
            }
        }
        .navigationDestination(item: $selected) { idx in
            Content3View()
                .environmentObject(model)
        }
    }
}

@available(iOS 15, *)
struct ContentViewIOS15: View {
    
    @EnvironmentObject var model: ContentModel
    
    let urls: [URL] = {
        (0..<50).map { URL(fileURLWithPath: "\($0)")}
    }()
    
    @State var selected: Int?
    
    var body: some View {
        List() {
            ForEach(urls.indices, id: \.self) { idx in
                let _ = urls[idx]
                NavigationLink(tag: idx, selection: $selected) {
                    if selected == idx {
                        Content3View()
                            .environmentObject(model)
                    }
                } label: {
                    Text("\(idx)")
                }
            }
        }
    }
}



struct Content3View: View {
    
    @EnvironmentObject private var model: ContentModel
    
    var body: some View {
        Text("duration: \(model.playbackDuration)")
        .onAppear() {
            model.load()
        }
    }
}


■ Investigation

The sample code has been tested on the iPhone 17.0 simulator, 15.2 simulator, and an iPhone 17.1 real device, but the issue only appears on the 17.2 beta. Also, when replacing NavigationStack with NavigationView in the sample code, the issue does not seem to occur on iOS 17.2.

I'm not sure about the relationship between the back navigation and toolbar inside NavigationStack, but it might be related to the following content in the iOS 17.2 Release Notes.

Resolved Issues
* Fixed: Resolved a possible Swift access conflict crash that could occur with toolbar items. (113992797)

This issue also brings to mind the randomness associated with NavigationView / NavigationStack that I've observed.

■ if anyone has found a workaround, please let me know.

I have not been able to confirm whether this issue occurs only on the Simulator, but it is preventing me from continuing to test on iOS 17.2 beta since the app is completely non-functional. If this is an issue with iOS 17.2 beta, I hope for a resolution before the official release of iOS 17.2.

Update:

I have tested on both the iPad Simulator and an actual iPad device.

iPad Simulator (iPadOS 17.2 (21C5029e)): The issue occurs

iPad real device (iPadOS 17.2 (21C5029g)): The issue does not occur

I haven't been able to confirm on an actual iPhone, but it might be an issue that occurs only on the Simulator.

It may be related to the thread below. Simulator crashing with iOS < 14. Started happening since Big Sur https://developer.apple.com/forums/thread/667921?page=2

We are having the same issue as described above on the iOS 17.2 simulator w Xcode 15.1 Beta 2.

Here is our output: [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000002e0d00> F8BB1C28-BAE8-11D6-9C31-00039315CD46 [aqme] AQMEIO.cpp:198 timed out after 15.000s (0 0); suspension count=0 (IOSuspensions: ) [aqme] MEDeviceStreamClient.cpp:467 AQME Default-InputOutput: client stopping after failed start: <CA_UISoundClientBase@0x103b6bee0>; running count now 0 CA_UISoundClient.cpp:293 CA_UISoundClientBase::StartPlaying: AddRunningClient failed (status = -66681). -[AVAssetTrack loadValuesAsynchronouslyForKeys:completionHandler:] invoked with unrecognized keys ("currentVideoTrack.preferredTransform"). [aqme] AQMEIO.cpp:198 timed out after 15.000s (0 0); suspension count=0 (IOSuspensions: ) [aqme] MEDeviceStreamClient.cpp:467 AQME Default-InputOutput: client stopping after failed start: <AudioQueueObject@0x1050fd600; Unknown FigPlayer; [2240]; play>; running count now 0 Warning: -[UITextInteractionAssistant selectionView] now returns nil with redesigned_text_cursor=on. [VisualTranslation] Visual isTranslatable: NO; reason: observation failure: noObservations [com.apple.VisionKit.RemoveBackground] Request to remove background on an unsupported device. Error Domain=com.apple.VisionKit.RemoveBackground Code=-8 "(null)" [com.apple.VisionKit.RemoveBackground] Error generating mask only remove background image for analysis: <VKCImageAnalysisResult: 0x103c4c230> - Error Domain=com.apple.VisionKit.RemoveBackground Code=-8 "(null)" [MADService] Client XPC connection invalidated

Similar issue on tvOS 17.2 simulator, Xcode 15.1 (released version). Same problem was with Xcode 14.3.1 and tvOS 16.4 simulator. On tvOS 16.4 at least I can hear audio, but video is not rendering). It works correctly only with Xcode 15.0 or 15.1 and tvOS simulator 17.0 (both audio and video working). Although Xcode 15.1 and tvOS simulator 17.0 still has issue that video does not quite start correctly, it's only after setting new stream that it recovers. It looks like simulator 17.2 is broken somehow and also Xcode 15.1 and its SDK introduced a bug, which prevents correct audio setup shortly after starting app.

Our app does not freeze, but video is not rendering and audio is not working in simulator (no problem on hardware).

Using Macbook Pro M3 96GB RAM, MacOS Sonoma 14.2.1.

               AQMEIO.cpp:198   timed out after 15.000s (0 0); suspension count=0 (IOSuspensions: )
 MEDeviceStreamClient.cpp:467   AQME Default-InputOutput: client stopping after failed start: <CA_UISoundClientBase@0x10983ae30>; running count now 0
     CA_UISoundClient.cpp:293   CA_UISoundClientBase::StartPlaying: AddRunningClient failed (status = -66681).
       MEMixerChannel.cpp:1006  MEMixerChannel::EnableProcessor: failed to open processor type 0x705f6571
{OptimizedCabacDecoder::UpdateBitStreamPtr} bitstream parsing error!!!!!!!!!!!!!!
{OptimizedCabacDecoder::EndSliceBody} bitstream parsing error!!!!!!!!!!!!!!
       MEMixerChannel.cpp:1006  MEMixerChannel::EnableProcessor: failed to open processor type 0x705f6571
{OptimizedCabacDecoder::UpdateBitStreamPtr} bitstream parsing error!!!!!!!!!!!!!!
{OptimizedCabacDecoder::EndSliceBody} bitstream parsing error!!!!!!!!!!!!!!
       MEMixerChannel.cpp:1006  MEMixerChannel::EnableProcessor: failed to open processor type 0x705f6571
{OptimizedCabacDecoder::UpdateBitStreamPtr} bitstream parsing error!!!!!!!!!!!!!!
{OptimizedCabacDecoder::EndSliceBody} bitstream parsing error!!!!!!!!!!!!!!
       MEMixerChannel.cpp:1006  MEMixerChannel::EnableProcessor: failed to open processor type 0x705f6571
               AQMEIO.cpp:198   timed out after 15.000s (0 0); suspension count=0 (IOSuspensions: )
 MEDeviceStreamClient.cpp:467   AQME Default-InputOutput: client stopping after failed start: <AudioQueueObject@0x10f18d400; Unknown figplayer; [3036]; play>; running count now 0

Seeing this on WatchOS 10.2 simulators also. App having when trying to play audio. Works fine on older versions on WatchOS 10.

I'm seeing this happen in a tvOS 17.2 simulator on Xcode 15.2 as well

I am seeing this on real devices using iOS 17.3 and XCode 15.2. Happens on iPhone XR. Seems to only happen when attached to XCode debugger. Note I am NOT using navigation in this app. My AVPlayers are in a scrollview.

I get multiple error messages, including:

[MADService] Client XPC connection invalidated

Visual isTranslatable: NO; reason: observation failure: noObservations

Error processing request from MAD on result: Error Domain=NSOSStatusErrorDomain Code=-128 "VCPMADServiceImageProcessingTask canceled" UserInfo={NSLocalizedDescription=VCPMADServiceImageProcessingTask canceled} request: <VKCImageAnalyzerRequest: 0x281f7c960> requestID: 13 madRequestID: 13 cancelled: YES

Hi,Bro I happen to meet the same issue on WatchOS 10 when trying to play audio. Have you resolve it now?

App Freezes with AVPlayer Inside NavigationStack on iOS 17.2 beta
 
 
Q