Post

Replies

Boosts

Views

Activity

Reply to SwiftUI - observing AVPlayer playback state
Hi, @breq The ItemModel above is almost right, except there is no need to store the AVPlayer in it. You can instantiate a single AVPlayer on app init, and set it as the player in a SwiftUI VideoPlayer instance. Then, when you want to play a certain video, you create an AVAsset using the URL in the Item and set it as the AVPlayer current item using: let asset = AVAsset(url: item.url) let playerItem = AVPlayerItem(asset: asset) player.replaceCurrentItem(with: playerItem) As for knowing when it pauses and plays, you can use a rate change observer in the class holding your AVPlayer like this: let name = AVPlayer.rateDidChangeNotification for await _ in NotificationCenter.default.notifications(named: name) { // in here you can read the player.rate, player.currentTime() and do your processing } Just remember that when the player is paused, it's rate == 0.0. Also, you should never set the rate directly. Use .pause() and .play() instead because the user may have chosen a different playing speed on the UI... Happy coding!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’24
Reply to Library missing
Hi! Just in case this helps others having the same issue in Mac Catalyst: I was having a very similar issue. The frameworks were there, and I followed the instructions above on the xcarchive app. The only thing missing was the LC_ID_DYLIB, which returned empty. In the end, I had deleted the Hardened Routine capability (https://developer.apple.com/documentation/security/hardened_runtime) from my (initially multi-platform) target when I found out some of my code would only run under Mac Catalyst and deleted macOS support to include it in the target. My frameworks were embedding and running fine on other platforms. It was only on Mac that the archived / TestFlight version was crashing and reporting missing frameworks with the following: Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: Namespace DYLD, Code 1 Library missing Library not loaded: @rpath/[framework_name_deleted].framework/Versions/A/[framework_name_deleted] Referenced from: <[uuid_deleted]> /Applications/[app_name_deleted]/Contents/MacOS/[app_name_deleted] Reason: , (security policy does not allow @ path expansion) (terminated at launch; ignore backtrace) Including the Hardened Routine back (with no exceptions in my case) made it run perfectly in TestFlight
Topic: App & System Services SubTopic: Core OS Tags:
Mar ’24