I'm looking for the MPMediaItem attribute that would allow me to sort my MPMediaPlaylist items array in the same order that it is showing up in the Music app. Anyone? Thanks.
Asked
Active
Viewed 600 times
2 Answers
0
This is fairly trivial, although not immediately obvious. Once you have your playlist, simply call the items
property instead of collections
.
For example:
MPMediaPlaylist *playlist = //..
// Loop through the items in the original order
for (MPMediaItem *item in playlist.items) {
NSLog(@"item: %@", item.title);
}
// Loop through the items sorted by title
for (MPMediaItemCollection *collection in playlist.collections) {
NSLog(@"collection: %@", collection.title);
}

squarefrog
- 4,750
- 4
- 35
- 64
0
let myPlaylistQuery = MPMediaQuery.playlists()
let playlists = myPlaylistQuery.collections
print(playlists as Any)
for playlist in playlists! {
print(playlist.value(forProperty: MPMediaPlaylistPropertyName)!)
let songs = playlist.items
for song in songs {
let songTitle = song.value(forProperty: MPMediaItemPropertyTitle)
print("\t\t", songTitle!)
}

deepak kumar
- 71
- 4
-
Please explain your answer a little – Ray Sep 13 '18 at 06:00