Post

Replies

Boosts

Views

Activity

Get Video Thumbnail Image Asynchronously
public func getVideoThumbnailImage(url: URL) -> Image { let urlAsset = AVURLAsset(url: url, options: nil) let assetImageGenerator = AVAssetImageGenerator(asset: urlAsset) assetImageGenerator.appliesPreferredTrackTransform = true assetImageGenerator.apertureMode = .encodedPixels let cmTime = CMTime(seconds: 1, preferredTimescale: 60) var thumbnailCGImage: CGImage? var errorOccurred = false let semaphore = DispatchSemaphore(value: 0) assetImageGenerator.generateCGImageAsynchronously(for: cmTime) { generatedImage, timeGenerated, error in if error == nil { if let cgVideoImage = generatedImage { thumbnailCGImage = cgVideoImage } else { errorOccurred = true } } else { errorOccurred = true } semaphore.signal() return } _ = semaphore.wait(timeout: .now() + 30) if errorOccurred { return Image("ImageUnavailable") } if let thumbnailImage = thumbnailCGImage { let uiImage = UIImage(cgImage: thumbnailImage) return Image(uiImage: uiImage) } return Image("ImageUnavailable") } I am using Xcode 16 beta 2 for iOS 18 with SwiftUI. My code above works instantly and correctly; however, Xcode produces the purple warning: "Thread running at User-interactive quality-of-service class waiting on a lower QoS thread running at Default quality-of-service class. Investigate ways to avoid priority inversions" How can I change the code to avoid the purple warning?
2
0
276
Jul ’24
SwiftUI Tabbed App does not work for More options
I was hoping that the options under the More button in a SwiftUI TabView app would be fixed in Xcode 11 GM. Unfortunately it still does not work!Tapping a More button option shows nothing under portrait device orientation. However, in landscape orientation when all my 7 tab bar items are visible the More options show their views.Other views in landscape orientation do not show until I swipe right to reveal it. Selecting an option does not completely show the view on right hand side.The default ContentView auto generated for a Tabbed App still shows the old code with selection @State var tags. No need for those any more. No need for VStack since it is the default. Why wasn't it updated to reflect the clean code in Xcode 11 GM?It seems to me that the Tabbed App is still work-in-progress. Why? It used to work very well under the UIKit! Tabbed apps are very commonly used and I am shocked that it does not work!
2
0
1.6k
Sep ’19