Jam*_*s64 2 mpmediaquery ios swift2
我一直在使用 Swift 2.3 编写音乐应用程序。我发现的问题是我的 MPMediaQuery.artistsQuery() 没有提供所有的艺术家。使用 iTunes,我已经追踪到如果“专辑是不同艺术家的歌曲汇编”被选中,那么该艺术家将不会出现在我的 tableView 中。例如,我使用 iTunes 导入的其中一张 CD(没有出现在我的 tableView 中)是:Little River Band,Greatest Hits。iTunes 似乎认为它是各种艺术家的合集,虽然我不同意,但我仍然需要处理这个场景。
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
}
Run Code Online (Sandbox Code Playgroud)
表中的所有部分都很好。我只是想念一些艺术家,包括:小河乐队。
此外,我的示例专辑中每首歌曲的艺术家标签都包含字符串:Little River Band。我似乎无法弄清楚为什么那个艺术家和其他一些人被排除在外。非常感谢您的帮助。
使用.songs()按 分组的查询artist似乎包括所有艺术家(包括那些只有合辑歌曲的艺术家)。
斯威夫特 3 示例:
let query = MPMediaQuery.songs()
query.groupingType = MPMediaGrouping.artist
Run Code Online (Sandbox Code Playgroud)
或者作为MPMediaQuery扩展:
extension MPMediaQuery {
public static func artistsAll() -> MPMediaQuery {
let query = MPMediaQuery.songs()
query.groupingType = MPMediaGrouping.artist
return query
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
let query = MPMediaQuery.artistsAll()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
512 次 |
| 最近记录: |