gpt4 book ai didi

ios - 如何播放 MPMediaItemCollection?

转载 作者:行者123 更新时间:2023-11-30 14:19:32 24 4
gpt4 key购买 nike

所以,我已经在 NSUserDefaults 中存储了一些mpmediaitemcollection。我已经在 UICollectionView 上检索到它。

这是我的代码:

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()

}

这是解码后的PlaylisData 数组:

(
"<MPMediaItemCollection: 0x165c5d00>",
"<MPMediaItemCollection: 0x165c6c30>",
"<MPMediaItemCollection: 0x165c7390>",
"<MPMediaItemCollection: 0x165c7c60>"
)

上面的代码应该根据indexPath.row播放每个mediaitemcollection

getSongListInfo 是一个获取所有信息(例如图像、标题、专辑、艺术家)的函数,并将其发送到一个结构体。它在另一个 vc 上的工作原理如下:

enter image description here

I can get song info from MPMediaItemCollection, but I can't play the song from MPMediaItemCollection

如何解决这个问题?

note: It actually play the MPMediaItemCollection, But when I clicked another UICollectionViewCell it's not playing

最佳答案

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

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

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

MPMusicPlayerController().play()

关于ios - 如何播放 MPMediaItemCollection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30663089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com