Bug: VideoPlayer View Crash

Using the VideoPlayer view in some macOS versions may result in a crash, with the following message:

failed to demangle superclass of VideoPlayerView from mangled name 'So12AVPlayerViewC'

Note that the crash only occurs when the app is not being debugged. This happens when you launch the app from Finder, instead of Xcode, or if you disable debugging mode from the project’s Scheme.

To make matters worse, the problem may not always manifest. It turns out that depending on your context the the view may or may not crash. For example, if an NSTextView with an embedded image attachment is presented before the VideoPlayer, the problem does not occur. This used to be my workaround, until I learnt the solution is much easier (see below).

Bug Report: FB8928032

Workaround: Yes, see below.

Fixed: Not yet.

Code Sample (to reproduce)

import SwiftUI
import AVKit

struct ContentView: View {
    let player = AVPlayer(url: Bundle.main.url(forResource: "myvideo", withExtension: "mp4")!)

    var body: some View {
        VideoPlayer(player: player)
            .frame(width: 640, height: 360)
    }
}

Workaround (UPDATE)

Fortunately, there is a simple workaround. You need to manually add the AVKit.framework to your “Link Binary With Libraries” build phase in Xcode:

6 thoughts on “Bug: VideoPlayer View Crash”

  1. Thanks for the tip. Lucky you to find it by chance. Looks like it’s related to dependencies in library loading.
    Anyway this doesn’t make me confident to use SwiftUI for real life commercial project !

    Reply

Leave a Comment

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close