Getting wrong playback state in MP Music Player Controller in ios 5(在 ios 5 中的 MP 音乐播放器控制器中出现错误的播放状态)
问题描述
我在 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 音乐播放器控制器中出现错误的播放状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 ios 5 中的 MP 音乐播放器控制器中出现错误的播


基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01