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.
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
Asked: 2023-05-31 23:35:53 +0000
Seen: 8 times
Last updated: Jun 01 '23
How can Django Admin accommodate a variety of formats and locales for its input fields?
How can an array be passed using typo3 flexform xml and itemsProcConfig?
Is it possible to invoke an asynchronous function without using the await keyword?
How can metadata be linked to a series in Polars?
What is the process of utilizing the map function to map a pandas column using a dictionary?
How can the orientation of images be corrected during uploading using Plupload?