I am using an MPMediaItemCollection
to hold a number of user selected music tracks from the iPod music library. I want to be able to uniquely identify each MPMediaItem
within the collection even if they are duplicated. Is this possible?
Asked
Active
Viewed 332 times
1

Sabobin
- 4,256
- 4
- 27
- 33
-
Is `-isEqual:` not sufficient? – Jonathan Grynspan Aug 08 '11 at 15:44
-
No. If the music players nowPlayingItem has duplicates in the media collection, if I check the nowPlayingItems index with NSArrays indexForObject: method, the mediaItem with the lowest index value is always returned. This means if the now playing item is one of the duplicates further up in the array it is not returning the correct object. I think indexForObject is using the isEqual: method to scan through the array until it returns true. – Sabobin Aug 08 '11 at 16:29
-
Yes, but that's always how it will work. That's the purpose of `-indexOfObject:`. If you want to find any duplicates, you cannot use `-indexOfObject:` because it will always give you the first index. – Jonathan Grynspan Aug 08 '11 at 16:33
-
Yeah exactly, thats why I need a way of uniquely IDing each mediaItem in the array so that I can be sure the right index is being returned for the music players nowPlayingItem – Sabobin Aug 08 '11 at 16:35
-
That doesn't make sense. If the item is in the list twice, *it's the same item twice*. – Jonathan Grynspan Aug 08 '11 at 16:36
-
I need to be able to differentiate such a way that I can look at the music players nowPlayingItem and know which index in the media collection it has come from. – Sabobin Aug 08 '11 at 16:41
-
Again, your question doesn't make sense, as the item could have come from either location since the item is present in both. What you want isn't quite possible. – Jonathan Grynspan Aug 08 '11 at 16:47
-
I want to be able to track the music players progress through the media collection, and then apply certain functionality based on where it is within the media collection. This is possible to do by retrieving the index for the nowPlayingItem provided there are no duplicates. But if there are duplicates present, there is no way of knowing where the player is within its que. The music player seems to create a que from the media collection that is passed to it, but there does not seem to be any way of directly accessing this . Can you see any way around this problem? I appreciate your help. – Sabobin Aug 08 '11 at 17:05
1 Answers
1
I've had the same problem as you, and Apple has just provided me the solution in iOS v5.0. There is an indexOfNowPlayingItem property in the MPMusicPlayerController class. You can use that to index into your array. This is of course if you are using MPMusicPlayerController.

hktegner
- 558
- 4
- 9