我正试图改写我的老玩家从目标C到斯威夫特(通过记忆),并陷入了麻烦。我有很多这样的歌曲
let query = MPMediaQuery.songsQuery()
query.groupingType = MPMediaGrouping.Title
songsArray = query.collections接下来,在我的表视图中,我试图获取要放在cell.textLabel中的每个媒体项的名称。如下所示:
var mediaItem = songsArray.objectAtIndex(indexPath.row)
var title = mediaItem.valueForProperty(MPMediaItemPropertyTitle)但是我没有得到MPMediaItems,我得到的是物品的集合。那么,我如何从MPMediaItem数组中获取MPMediaItemCollections并获得标题呢?
发布于 2015-02-19 14:54:36
如果要使用媒体项的集合分组并获取其中的轨道组的信息,则可以通过MPMediaItemCollection的representativeItem属性访问集合内容的representativeItem表示。
let collection = songsArray.objectAtIndex(indexPath.row) as! MPMediaItemCollection
let representativeItem = collection.representativeItem
let title = representativeItem.title附带注意,如果您希望处理一个MPMediaItems数组,您可能需要考虑使用MPMediaQuery的items属性,而不是它的collections属性。
https://stackoverflow.com/questions/28608968
复制相似问题