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 音乐播放器控制器中出现错误的播
基础教程推荐
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
