我正在寻找MPMediaItem属性,该属性允许我按照音乐应用程序中显示的顺序对MPMediaPlaylist项数组进行排序。任何人谢谢
这是相当琐碎的,尽管不是很明显。一旦您有了播放列表,只需调用items
属性而不是collections
。
例如:
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);
}
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("tt", songTitle!)
}