首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios -如何播放MPMediaItemCollection?

ios -如何播放MPMediaItemCollection?
EN

Stack Overflow用户
提问于 2015-06-05 09:32:46
回答 1查看 625关注 0票数 0

因此,我已经在NSUserDefaults中存储了很少的NSUserDefaults。我已经在UICollectionView上检索了它。

这是我的代码:

代码语言:javascript
复制
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    self.performSegueWithIdentifier("toList", sender: self)

    User.mdci = decodedPlaylistData[indexPath.row] as? MPMediaItemCollection

    getSongListInfo((decodedPlaylistData[indexPath.row] as? MPMediaItemCollection)!)

    MPMusicPlayerController().setQueueWithItemCollection((decodedPlaylistData[indexPath.row] as? MPMediaItemCollection)!)
    MPMusicPlayerController().nowPlayingItem = (decodedPlaylistData[indexPath.row] as? MPMediaItemCollection)!.items[0] as! MPMediaItem

    MPMusicPlayerController().play()

}

下面是decodedPlaylisData数组:

代码语言:javascript
复制
(
"<MPMediaItemCollection: 0x165c5d00>",
"<MPMediaItemCollection: 0x165c6c30>",
"<MPMediaItemCollection: 0x165c7390>",
"<MPMediaItemCollection: 0x165c7c60>"
)

上面的代码应该根据indexPath.row播放每个媒体集合。

getSongListInfo是一个获取图像、标题、相册、艺术家等所有信息的函数,我将其发送到一个结构中。它的工作原理如下所示:

我可以从MPMediaItemCollection获得歌曲信息,但是我不能播放MPMediaItemCollection的歌曲

我怎样才能解决这个问题?

注意:它实际上是在播放MPMediaItemCollection,但是当我单击另一个UICollectionViewCell时,它不会播放

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-05 18:24:12

此代码创建三个独立的音乐播放器控制器。创建一个并将其存储在一个变量中,然后将消息发送给它。

代码语言:javascript
复制
MPMusicPlayerController().setQueueWithItemCollection((decodedPlaylistData[indexPath.row] as? MPMediaItemCollection)!)

MPMusicPlayerController().nowPlayingItem = (decodedPlaylistData[indexPath.row] as? MPMediaItemCollection)!.items[0] as! MPMediaItem

MPMusicPlayerController().play()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30663089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档