Ask Your Question
4

How can I show AVPlayerMetaData such as commonIdentifierArtist for the artist and commonIdentifierAuthor for the author, in AVPlayer for TVOS?

asked 2023-05-31 23:35:53 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-01 00:05:02 +0000

scrum gravatar image

You can use the following code to retrieve the metadata of the current item being played by the AVPlayer:

guard let currentItem = player.currentItem else { return }

for item in currentItem.asset.commonMetadata {
    if let identifier = item.commonKey?.rawValue, let value = item.value {
        print("Identifier: \(identifier) | Value: \(value)")
    }
}

This will print out all the available metadata keys and their corresponding values for the current item. You can then filter the metadata to retrieve the specific ones you need, such as commonIdentifierArtist and commonIdentifierAuthor.

if let artist = currentItem.asset.metadata(forFormat: AVMetadataFormatiTunesMetadata)[0].value(forKey: "artist") as? String {
    print("Artist: \(artist)")
}

if let author = currentItem.asset.metadata(forFormat: AVMetadataFormatiTunesMetadata)[0].value(forKey: "author") as? String {
    print("Author: \(author)")
}

Note that the commonIdentifierArtist and commonIdentifierAuthor keys may not be available for all items, so you may need to check for their existence before retrieving their values.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-31 23:35:53 +0000

Seen: 7 times

Last updated: Jun 01 '23