Get date when MPMediaItem was added to iTunes libr

2019-07-04 06:19发布

问题:

Is it possible? I haven't found anything like this in MPMediaItemProperty... strings. Maybe private API?

回答1:

Looking through the documentation, the methods list doesn't have a field for it. This leaves you with the option of extending MPMediaItem with a new MPMediaItemProperty for the 'date added' field yourself. Of course, this only works going forward.

Alternatively, you could parse the iTunes Library XML item and compare fields to the MPMediaItem you're using. There is a key tag for 'Date Modified' that has the conventional filesystem 'Date Modified' information (presumably from when the file was added to iTunes), but which is basically when the file was ripped or added unless you're modifying your MP3 files. So it's not strictly what you're looking for, but it's the closest general analogue I can think of.

You may want to see if there is a way of finding the Track ID key directly from the file or MPMediaItem as well which may give you a faster search through the iTunes Library XML file. Try the MPMediaItemPropertyPersistentID-based methods---one of these should correspond to the hex identifier in the 'Persistent ID' key field of the iTunes Library XML file.



回答2:

https://stackoverflow.com/a/38826548/899490

As of iOS 10 it appears we have access to two dateAdded properties.

Note: iOS 10 is still in beta (4) at time of writing so things could change.

As a Date object:

MPMediaItem.dateAdded

and as a String:

MPMediaItemPropertyDateAdded

source: https://developer.apple.com/library/prerelease/content/releasenotes/General/iOS10APIDiffs/Objective-C/MediaPlayer.html