Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How unique is MPMediaItemPropertyPersistentID?

How unique is MPMediaItemPropertyPersistentID? Will it even work when synching the list of IDs to another device connected to the same iTunes Account?

I want to implement a iCloud synchronized playlist solution which stores the IDs as a list and I need to know if this will be possible.

like image 805
miho Avatar asked Aug 30 '12 11:08

miho


4 Answers

As per the documentation (emphasis mine)...

The value of the MPMediaItemPropertyPersistentID identifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.

As such, given that it won't even persist on this basis I'd be surprised if it persisted across devices in a sufficiently robust manner, if at all.

like image 200
John Parker Avatar answered Nov 13 '22 15:11

John Parker


In my understanding this is not possible. I think this ID is persistent only for each device. It is no unique identifier for a specific song in the iTunes Store. It is only a ID for your own synced songs.

As you read the documentation, you'll see how fragile this ID could be.

"The value is not guaranteed to persist across a sync/unsync/sync cycle."

So if you sync your song database with iTunes and maybe delete a song from your iOS device and the sync again and put it back to your device, you may not get the same ID again for this song. And for sure not across other devices.

So I think, what you're trying to do will not work, until you get a worldwide identical Identifier for each song of the iTunes catalogue or your own iTunes catalogue on the Mac (where the Mac has to handle the IDs).

like image 34
Fab1n Avatar answered Nov 13 '22 16:11

Fab1n


The other answers are a little big vague, so here is an answer from my own experiences and tests:

1) You can't use MPMediaItemPropertyPersistentID to get an ID that is equal between devices.
2) The MPMediaItemPropertyPersistentID will change when the device is synced with another iTunes library or all music is removed from the device and then synced again.

The ID get's created and stored by iTunes when the song is synced on the device. If it's unsynced, the ID get's deleted.

like image 2
Fabian Kreiser Avatar answered Nov 13 '22 15:11

Fabian Kreiser


In case somebody else lands here, like me, using a Google search:

I confirmed what middaparka said above after an iOS upgrade of my device, when my music app tried to use persistentIDs from before the upgrade. The IDs had changed, and I ended up (unwittingly) listening to many songs from my library that I don't normally listen to...

So I took middaparka's advice and constructed a persistentKey by exclusive-oring the hashes from title, artistName, albumTitle and duration. Building the persistentKey during Core Database initialization will be save time later, by avoiding multiple string comparisons when fetching items in "normal operating code."

The persistentKey strategy worked properly for songs. However, when I made a hash for albums from title, artist and releaseYear, I ended up with one collision.

I had two self-titled albums by different artists released in 1976. When the hashes for the album title and the artist were exclusive-ored, they cancelled each other out. I ended up using the hash for the duration instead of the artist, and that worked.

I may end up refining the algorithm for generating the persistentKeys later...

like image 2
Carl Smith Avatar answered Nov 13 '22 15:11

Carl Smith