为什么 MPMusicPlayerController 调用其正在播放的项目更改选择器方法两次?
我正在为 iPhone 编写一个音乐播放列表编辑应用程序。
我正在订阅
MPMusicPlayerController
MPMusicPlayerControllerNowPlayingItemDidChangeNotification
我是 此通知的@selector
方法出现问题 当nowPlayingItem:
更改时被多次调用。
我已将每个播放列表划分为各自的 MPMediaItemCollection
对象,当一个播放列表完成后,我通过在播放器上调用 -pause
来加载下一个播放列表,并传递一个新的 < code>MPMediaItemCollection 通过其 -setQueueWithItemCollection:
方法连接到音乐播放器控制器。然后,我将 nowPlayingItem 显式设置为我自己的一个项目,最后调用 -play
。
[musicPlayer pause];
[musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:[selectedPrefs mediaItems]]];
musicPlayer.nowPlayingItem = [selectedPrefs.playbackItems objectAtIndex:selectedPrefs.nowPlayingIndex];
[musicPlayer play];
当我这样做时,@selector
会被调用两次以更改当前播放的项目。我怀疑这是因为 -setQueueWithItemCollection:
自动更改正在播放的项目以指向新集合中的第一个媒体项目,然后我在调用 -play
之前再次更改此项目代码>.
非常感谢。
I am writing a music playlist editing application for the iPhone.
I am subscribing to the
MPMusicPlayerController
MPMusicPlayerControllerNowPlayingItemDidChangeNotification
and I am
getting a problem where the@selector
method for this notification
is being called more than once when thenowPlayingItem:
changes.
I have divided up each playlist into their own MPMediaItemCollection
objets, and when one playlist is finished I load the next one, by calling -pause
on the player, passing a new MPMediaItemCollection
to the music player controller via its -setQueueWithItemCollection:
method. I then explicitly set the nowPlayingItem to an item of item of my own and finally I call -play
.
[musicPlayer pause];
[musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:[selectedPrefs mediaItems]]];
musicPlayer.nowPlayingItem = [selectedPrefs.playbackItems objectAtIndex:selectedPrefs.nowPlayingIndex];
[musicPlayer play];
When I do this the @selector
is called twice for the now playing item changing. I suspect this is because -setQueueWithItemCollection:
automatically changes the now playing item to point to the first media item in the new collection, and then I am changing this item again before calling -play
.
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论