I have been writing a music app using Swift 2.3. The trouble that I've found is that my a MPMediaQuery.artistsQuery() doesn't provide all of the artists. Using iTunes, I've tracked it down to if "Album is a compilation of songs by various artists" is checked, then that artist will not show up in my tableView. For example, one of the CD's (which doesn't show up in my tableView) that I imported using iTunes is: Little River Band, Greatest Hits. iTunes seems to think that it is a compilation of various artists, and while I disagree, I still need to handle the scenario.
var qryArtists = MPMediaQuery.artistsQuery()
qryArtists.groupingType = MPMediaGrouping.Artist
// Set the cell in the table
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// I am using the custom class that I created called: myCustomArtistTableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier("artistIdCell", forIndexPath: indexPath) as! myCustomArtistTableViewCell
let currLoc = qryArtists.collectionSections![indexPath.section].range.location
let rowItem = qryArtists.collections![indexPath.row + currLoc]
cell.artistTitle.text = rowItem.items[0].artist
return cell
}
All of the sections in the table are fine. I am just missing a few artists including: Little River Band.
Also, the artist tag on every song on my example album, contains the string: Little River Band. I just can't seem to figure out why that artist and a few others are being excluded. Thank you very much for any help.
Using a .songs()
query, grouped by artist
, seems to include all artists (including those with just compilation songs).
Swift 3 example:
let query = MPMediaQuery.songs()
query.groupingType = MPMediaGrouping.artist
Or as a MPMediaQuery
extension:
extension MPMediaQuery {
public static func artistsAll() -> MPMediaQuery {
let query = MPMediaQuery.songs()
query.groupingType = MPMediaGrouping.artist
return query
}
}
Usage:
let query = MPMediaQuery.artistsAll()