说明:我正试图设置identifier中AVMetadataItem的swift3,如this apple video中所述。不过,这段视频是在“迅捷3”之前拍摄的。在swift2中,它看起来像这样:let metadataItem = AVMetadataItem(identifier: AVMetadataCommonIdentifierTitle, value: "Title here")但是,在swift3中,构造函数不再存在。有一个空构造函数,此构造函数为:AVMetadataItem(propertiesOf: AVMetadataItem, valueLoadingHandler: (AVMetadataItemValueRequest) -> Void)似乎没有任何方法可以设置 >。问题:如何在identifier中设置identifier的AVMetadataItem?编辑:按照卢卡斯的建议,尝试使用avmutablemetadataitem()。private func setupNavigationMarker(title: String, description: String, timeRange: CMTimeRange)-> AVTimedMetadataGroup { var items: [AVMetadataItem] = [] let titleItem = AVMutableMetadataItem() titleItem.identifier = AVMetadataCommonIdentifierTitle titleItem.value = title as (NSCopying & NSObjectProtocol)? items.append(titleItem) let descriptionItem = AVMutableMetadataItem() descriptionItem.identifier = AVMetadataCommonIdentifierDescription descriptionItem.value = description as (NSCopying & NSObjectProtocol)? items.append(descriptionItem) return AVTimedMetadataGroup(items: items, timeRange: timeRange)}在这里使用: let cmTimeStart = CMTimeMake(0, 0) let cmTimeDuration = CMTimeMake(10, 1) let timeRange = CMTimeRange(start: cmTimeStart, duration: cmTimeDuration) let timedMetadataGroup = self.setupNavigationMarker(title: "test", description: "description test" , timeRange: timeRange) let timedMetadataGroupList = [timedMetadataGroup] let navigationMarkersGroup = AVNavigationMarkersGroup(title: "Chapters", timedNavigationMarkers: timedMetadataGroupList) //predefined avPlayerItem avPlayerItem.navigationMarkerGroups.append(navigationMarkersGroup)它编译并运行,但在播放视频时不建议使用导航标记(也称为章节)。我错过了什么? 最佳答案 使用AVMutableMetadata而不是AVMetadata,这样您可以根据自己的选择修改identifier。let titleItem = AVMutableMetadataItem()titleItem.identifier = AVMetadataCommonIdentifierTitle关于swift - 如何在swift3中设置AVMetadataItem的标识符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39612162/
10-13 09:30