【问题标题】:How to set the identifier of AVMetadataItem in swift3?如何在swift3中设置AVMetadataItem的标识符?
【发布时间】:2016-09-21 09:09:22
【问题描述】:

说明:

我正在尝试在swift3 中设置AVMetadataItemidentifier,就像this apple video 中提到的那样。但是,该视频是 swift3 之前的视频。

swift2 中看起来像这样:

let metadataItem = AVMetadataItem(identifier: AVMetadataCommonIdentifierTitle, value: "Title here")

但是,在swift3 中,该构造函数不再存在。

有一个空的构造函数和这个:

AVMetadataItem(propertiesOf: AVMetadataItem, valueLoadingHandler: (AVMetadataItemValueRequest) -> Void)

似乎没有任何方法可以设置identifier

问题:

如何在swift3 中设置AVMetadataItemidentifier

编辑:

按照 Lucas 的建议尝试使用 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)

它可以编译并运行,但在播放视频时没有建议导航标记(也称为章节)。我错过了什么?

【问题讨论】:

    标签: swift swift3 tvos avmetadataitem


    【解决方案1】:

    使用AVMutableMetadata 代替AVMetadata 这样您就可以随意修改identifier

    let titleItem =  AVMutableMetadataItem()
    titleItem.identifier = AVMetadataCommonIdentifierTitle
    

    【讨论】:

    • 您尝试过使用 AVMutableMetadataItem 实例吗? “要为您自己的资产创建元数据项,您可以使用可变子类 AVMutableMetadataItem。”
    • @LucasDavanzo 我实际上没有。我会玩弄它,看看它是否有效。感谢您的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 2012-04-19
    相关资源
    最近更新 更多