11
A
回答
21
使用MPMediaQuery:
MPMediaQuery *allAlbumsQuery = [MPMediaQuery albumsQuery];
NSArray *allAlbumsArray = [allAlbumsQuery collections];
的allItems陣列確實現在包含MPMediaItemCollections,分組按專輯完成。現在你可以遍歷數組了。
for (MPMediaItemCollection *collection in allAlbumsArray) {
MPMediaItem *item = [collection representativeItem];
}
4
感謝您的回答,打印出的專輯和藝術家的情況下,有人在這裏工作的示例代碼需要它:
NSMutableString *outText = [[NSMutableString alloc] initWithString:@"Albums:"];
[outText appendFormat:@"\r\n count:%i",[[[MPMediaQuery albumsQuery] collections] count]];
for (MPMediaItemCollection *collection in [[MPMediaQuery albumsQuery] collections]) {
[outText appendFormat:@"\r\n -%@",[[collection representativeItem] valueForProperty:MPMediaItemPropertyAlbumTitle]];
}
[outText appendString:@"\r\n\r\n Artist:"];
for (MPMediaItemCollection *collection in [[MPMediaQuery artistsQuery] collections]) {
[outText appendFormat:@"\r\n -%@",[[collection representativeItem] valueForProperty:MPMediaItemPropertyArtist]];
}
NSLog(@"%@",[outText autorelease]);
0
在這裏你去。你可以得到專輯和他們的歌曲。
/// Get all albums and their songs
///
func getAllAlbums() {
let query: MPMediaQuery = MPMediaQuery.albums()
let allAlbums = query.collections
allAlbumItems?.removeAll()
guard allAlbums != nil else {
return
}
for collection in allAlbums! {
let item: MPMediaItem? = collection.representativeItem
let albumName = item?.value(forKey: MPMediaItemPropertyAlbumTitle) as? String ?? "<Unknown>"
let albumId = item!.value(forProperty: MPMediaItemPropertyAlbumPersistentID) as! NSNumber
let artistName = item?.value(forKey: MPMediaItemPropertyArtist) as? String ?? "<Unknown>"
let album = Album()
album.name = albumName
album.artistName = artistName
album.albumId = String(describing: albumId)
print("Album name: \(albumName)")
// Get all songs in this album
let mediaQuery = MPMediaQuery.songs()
let predicate = MPMediaPropertyPredicate.init(value: albumId, forProperty: MPMediaItemPropertyAlbumPersistentID)
mediaQuery.addFilterPredicate(predicate)
let song = mediaQuery.items
if let allSongs = song {
var index = 0
for item in allSongs {
let pathURL: URL? = item.value(forProperty: MPMediaItemPropertyAssetURL) as? URL
if pathURL == nil {
print("@Warning!!! Track : \(item) is not playable.")
} else {
let trackInfo = SongItem()
trackInfo.index = index
trackInfo.mediaItem = item
let title = item.value(forProperty: MPMediaItemPropertyTitle) as? String ?? "<Unknown>"
let artistName = item.value(forProperty: MPMediaItemPropertyArtist) as? String ?? "<Unknown>"
trackInfo.songName = title
trackInfo.artistName = artistName
trackInfo.isSelected = false
trackInfo.songURL = item.value(forProperty: MPMediaItemPropertyAssetURL) as? URL
album.songs?.append(trackInfo)
index += 1
}
}
}
// Finally add the album object to albums array
allAlbumItems?.append(album)
}
print("Total Album count: \(allAlbumItems?.count)")
}
相關問題
- 1. 獲取一位藝術家的所有專輯
- 2. Android:MediaStore缺少藝術家和專輯
- 3. MPMedia按藝術家加載專輯
- 4. 使用eyed3設置「專輯藝術家」?
- 5. 從MP3獲取專輯藝術PHP
- 6. 如何查詢給定的藝術家的所有專輯
- 7. 如何獲取iOS中的音樂的藝術家,專輯等
- 8. 獲取當前歌曲的藝術家和專輯foobar2000
- 9. SPAlbumBrowse - 獲取藝術家專輯的準確名單
- 10. 如何獲取標籤mp3 java藝術家專輯年
- 11. 從MediaStore獲取藝術家藝術
- 12. Android專輯藝術
- 13. 使用Gracenote獲取有關音樂藝術家,專輯和曲目的信息
- 14. 如何獲得每位藝術家的最高評分專輯?
- 15. Ruby-mp3info專輯藝術品
- 16. ChromeCast SDK專輯藝術
- 17. MPMoviePlayer音頻專輯藝術
- 18. 專輯藝術品從MP3
- 19. freedb.org - 如何查詢藝術家/專輯沒有光盤ID
- 20. 如何獲取音頻文件信息(專輯,藝術家,圖像,...)Android?
- 21. 如何從Spotify Web API獲取藝術家的前5個專輯?
- 22. 獲取圖上繪製的所有對象(藝術家)
- 23. 如何獲取用戶的所有藝術家(Spotify Api 1.x)?
- 24. 獲取UWP音樂文件藝術家藝術/縮略圖
- 25. 選擇藝術家專輯列表並顯示每個專輯中已經請求了藝術家和專輯的列表中的曲目數量
- 26. Matplotlib:刪除所有藝術家和線
- 27. 爲所有藝術家查詢https://musicbrainz.org
- 28. Spotify API在瀏覽藝術家時返回太多專輯
- 29. 刪除「專輯藝術家」ID3標籤與bash?
- 30. 使用Spotify API查找專輯的藝術家