PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 29, 2022

[FIXED] How to set the identifier of AVMetadataItem in swift3?

 September 29, 2022     avmetadataitem, swift, swift3, tvos     No comments   

Issue

Description:

I'm attempting to set the identifier of AVMetadataItem in swift3, like mentioned in this apple video. However, the video is pre-swift3.

In swift2 it would look something like this:

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

However, in swift3 that constructor does not exist anymore.

There is an empty constructor and this one:

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

There does not seem to be any methods that exist to set the identifier.

Question:

How do I set the identifier of AVMetadataItem in swift3?

Edit:

Tried with AVMutableMetadataItem() as suggested by Lucas.

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)

}

and here in use:

    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)

It compiles and runs but no navigation markers (aka chapters) are proposed when the video plays. What am I missing?


Solution

Use AVMutableMetadata instead of AVMetadata this way you can modify the identifier as you choose to.

let titleItem =  AVMutableMetadataItem()
titleItem.identifier = AVMetadataCommonIdentifierTitle


Answered By - Luca Davanzo
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing