I'm running into an issue trying to create a link to fileImporter as part of a list of options.
I have an enum of options that will be presented in a sidebar-style list menu:
enum MenuOption: Identifiable, CaseIterable {
var id: Int { self.hashValue }
case import
case optionB
case optionC
case optionD
case optionE
@ViewBuilder
var destination: some View {
switch self {
case .import: ImportView(isPresented: .constant(true), progress: ImportProgress())
case .optionB: OptionBView()
// etc
}
}
And I am iterating over the enum as follows:
struct SidebarMenuView: View {
@State private var selection : MenuOption? = nil
var body: some View {
List(selection: $selection) {
ForEach(MenuOption.allCases) { option in
Button(action: { self.selection = option} ) {
option.label
}
.sheet(item: $selection) { sheet in
sheet.destination
}
}
}
}
}
However, presenting fileImporter as its own view causes the interface to crash. It has to be attached to something as a view modifier. The workaround suggested on SO is to attach it to Color.clear:
struct ImportView: View {
@Binding var isPresented: Bool
@ObservedObject var progress: ImportProgress
var body: some View {
Color.clear
.fileImporter(
isPresented: $isPresented,
allowedContentTypes: [ ... ],
allowsMultipleSelection: true) { result in
if let urls = try? result.get() {
do { // stuff }
}
}
}
But the result of is this that, after fileImporter has been dismissed, there's an empty sheet still displayed which has to be dismissed separately, and I can't find a way around that.
Post
Replies
Boosts
Views
Activity
I'm working on a media metadata tagging library, and the only source I can find for a list of the pre-defined genres in use with iTunes/Quicktime is on the ExifTool website for QuickTime GenreID and I have no way of knowing how current it is. If possible, I would rather use whatever enum Apple already provides for this, if it's available, but I haven't been able to find it. Can anyone point me in the right direction?
I'm creating a Swift library for handling metadata tagging and adding/modifying chapters in .m4a/.m4b audio files. It's not intended to re-encode, so I need to be able to use the `AVAssetExportPresetPassthrough`.I was doing fine with the metadata using AVAssetExportSession, but if there's a way to add an `[AVTimedMetadataGroup]` array to an export session, I haven't found it.I've seen a lot of older posts in various places in regarding adding timed metadata to video and saving using AVAssetWriter in Objective-C, but I'm having trouble implementing them in Swift and I'm just not familiar with using AVAssetWriter. None of the methods I've tried have worked.// get the source audio track
let audioTrack = asset.tracks(withMediaType: .audio).first
let audioDesc = audioTrack?.formatDescriptions as! CMFormatDescription
// turn it into an Input
let audioInput = AVAssetWriterInput(
mediaType: .audio,
outputSettings: nil,
sourceFormatHint: audioDesc)
var writer = try AVAssetWriter(outputURL: outputUrl, fileType: .m4a)
var timedMetadata: [AVTimedMetadataGroup] = [...]
for group in timedMetadata {
let desc = group.copyFormatDescription()
// create text input
let textInput = AVAssetWriterInput(mediaType: .text,
outputSettings: nil,
sourceFormatHint: desc)
textInput.marksOutputTrackAsEnabled = false
textInput.expectsMediaDataInRealTime = false
let metadataAdaptor = AVAssetWriterInputMetadataAdaptor(
assetWriterInput: textInput)
textInput.requestMediaDataWhenReady(on: DispatchQueue(label: "metadataqueue", qos: .userInitiated), using: {
metadataAdaptor.append(group)
})
if audioInput.canAddTrackAssociation(
withTrackOf: textInput, type: AVAssetTrack.AssociationType.chapterList.rawValue) {
audioInput.addTrackAssociation(
withTrackOf: textInput, type: AVAssetTrack.AssociationType.chapterList.rawValue)
}
if writer.canAdd(textInput) {
writer.add(textInput)
}
}
if writer.canAdd(audioInput) {
writer.add(audioInput)
}So basically, where I'm starting out from, I've got an audio asset, an `[AVMetadataItem]` array, and an `[AVTimedMetadataGroup]` array, and I need to get them all into a single file at pass-through quality. I know what I have here is wrong, but I don't know how to fix it. Currently it writes a corrupt, zero-byte file.