問題描述
我在 MP 音樂播放器中的播放狀態錯誤.在播放歌曲時,我處于暫停狀態.我的應用程序在 ios 4 中運行良好.但我在 ios 5 中遇到了這個問題.誰能幫幫我??
i am getting wrong playback state in MP music player. while playing a song i am getting pause state. My app is working fine in ios 4.but i am having this issue in ios 5. can anybody Help me ??
我的代碼在這里.
[musicPlayer stop];
if (userMediaItemCollection)
{
userMediaItemCollection=nil;
}
musicPlayer.nowPlayingItem=nil;
userMediaItemCollection=[MPMediaItemCollection collectionWithItems:[mediaItemCollection items]];
[musicPlayer setQueueWithItemCollection:userMediaItemCollection];
[musicPlayer setNowPlayingItem:
[[userMediaItemCollectionitems]objectAtIndex:indexOfCurrentObject]];
[self enablePrevAndNextButtons];
[musicPlayer play];
}
-(void)playbackStateDidChanged:(NSNotification *)notification
{
if (musicPlayer.playbackState!=MPMusicPlaybackStatePlaying)
{
[playPauseButton setBackgroundImage:[UIImage imageNamed:@"play_iPad.png"] forState:UIControlStateNormal];
}
else if(musicPlayer.playbackState==MPMusicPlaybackStatePlaying)
{
[playPauseButton setBackgroundImage:[UIImage imageNamed:@"pause_iPad.png"] forState:UIControlStateNormal];
}
推薦答案
我也向 Apple 報告了這個錯誤.通過執行以下操作,我能夠 100% 地重現它:
I have also reported this bug to Apple. I was able to reproduce it 100% of the time by doing the following:
啟動使用 MPMusicPlayerController 的應用程序.啟動音樂"應用程序.點擊播放,跳過,跳過,暫停,播放,暫停打開原應用,MPMusicPlayerController的MPMusicPlaybackState會出錯.
Launch application that uses MPMusicPlayerController. Launch the "Music" App. Hit Play, Skip, Skip, Pause, Play, Pause Open the original application and the MPMusicPlaybackState of MPMusicPlayerController will be incorrect.
這里提出的解決方案都不適合我.有效的解決方案是跟蹤錯誤發生的時間并在這些情況下特別更新 UI.
None of the proposed solutions here worked for me. The solution that did work was to keep track of when the bug was occurring and updating the UI specially in these cases.
當收到 UIApplicationDidBecomeActiveNotification
通知時(有關這方面的更多詳細信息,請參閱 matbur 帖子),查看當 MPMusicPlaybackState 說它是時音頻是否實際上沒有播放:
When the UIApplicationDidBecomeActiveNotification
notification is received (see matbur post for more details on this), see if audio is actually not playing when the MPMusicPlaybackState said it was:
-(BOOL) isPlaybackStateBugActive {
MPMusicPlaybackState playbackState = self.musicPlayer.playbackState;
if (playbackState == MPMusicPlaybackStatePlaying) {
AudioSessionInitialize (NULL, NULL, NULL, NULL);
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);
AudioSessionSetActive (true);
UInt32 audioIsPlaying;
UInt32 size = sizeof(audioIsPlaying);
AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &size, &audioIsPlaying);
if (!audioIsPlaying){
NSLog(@"PlaybackState bug is active");
return YES;
}
}
return NO;
}
別忘了導入 AudioToolbox 框架.
Don't forget to import the AudioToolbox framework.
這篇關于在 ios 5 中的 MP 音樂播放器控制器中出現錯誤的播放狀態的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!