osx - How do I access the title of an iTunes song using MLMediaLibrary and Swift on macOS? -


i'm using apple's medialibrary framework on macos, write application reads in information on every song in itunes library.

i'm able extract artist of song, using mlmediaobjectartistkey key in attributes dictionary (property on mlmediaobject), how access title of song?

from can tell documentation, seems information (the title) not provided through attributes dictionary.

have others had luck retrieving title, , if so, how?

on mlmediaobject:

  • you can use .name attribute:
print("\(mediaobj.attributes[mlmediaobjectartistkey]!), \(mediaobj.name!)") // swift 
  • or can use "name" key dictionary object:

mediaobj.attributes["name"]


to keys dictionary:

print(array(mediaobj.attributes.keys)) // swift 

Comments