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:
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 !
I updated the post with a better workaround.
OMG! you saved me a lot of time.
I thank you for that
Seams like the workaround does not work anymore 🙁
Thanks for this, this was the exact issue we had as well.
Thank you from 2023!