我正在使用来自NSNotificationCenter的通知来获取MPMusicPlayerController通知。
我使用这些通知将视图中按钮的状态从“播放”状态更改为“暂停”状态。
它“工作”但是有时MPMusicPlayerController (确切地说是iPodMusicPlayer)不能报告正确的状态,因此我的按钮变得一团糟,不能正确操作。
在做了一些调查后,我发现当改变当前播放的歌曲时,会触发很多通知。
例如:当我选择一首歌时,我会调用:- stop - setQueueWIthItemCOllection - nowPlayingItem - play
这些调用,启动了这么多通知。在停止之后,我收到两次nowPlayingItem的通知,例如在nowPlayingItem调用之后...???
此外,即使强制我的按钮相对于它们的“图片”状态而不是MPMusicPlayerController播放状态进行操作,控制器仍然不能反映正确的状态。例如,一首歌曲将在背景中播放(我可以听到,“播放”图标在ipad最右上角的电池图标旁边是打开的),但MPMusicPlayerController iPodMusicPlayer报告状态为"Pause“……
有没有人有这方面的信息或帮助?
干杯
发布于 2012-08-15 15:56:01
我相信我也有同样的问题,我发现我必须做两件事来解决它:
1)复制传入的MPMediaItemCollection的items数组并使用它创建一个新的MPMediaItemCollection
2)在播放器上设置nowPlayingItem和/或currentPlaybackTime
一旦我做了这两件事,我从音乐播放器收到的通知就会生成预期的次数,而且它们都有准确的playbackStates (反映播放器的实际状态)。
希望这能对你有所帮助。
-(void)setUserMediaItemCollection:(MPMediaItemCollection *)newUserMediaItemCollection
{
[userMediaItemCollection release];
//I FOUND YOU MUST COPY THE INCOMING ITEMS TO A NEW COLLECTION
NSArray *combinedMediaItems = [newUserMediaItemCollection.items copy];
userMediaItemCollection = [[MPMediaItemCollection collectionWithItems: (NSArray *) combinedMediaItems] retain];
[combinedMediaItems release];
[self.musicPlayer setQueueWithItemCollection:userMediaItemCollection];
//
//ALSO FOUND YOU MUST SET EITHER THE NOWPLAYING ITEM OR STARTTIME OR PLAYBACK STATE CAN BE WRONG
if ([[userMediaItemCollection items] count])
{
//MPMediaItem *nowPlayingItem = [[userMediaItemCollection items] objectAtIndex:0];
//[self.musicPlayer setNowPlayingItem:nowPlayingItem];
NSTimeInterval startTime = 0.0;
musicPlayer.currentPlaybackTime = startTime;
}
//
}https://stackoverflow.com/questions/10806221
复制相似问题