在 ios 5 中的 MP 音乐播放器控制器中出现错误的播放状态 [英] Getting wrong playback state in MP Music Player Controller in ios 5

查看:19
本文介绍了在 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 音乐播放器控制器中出现错误的播放状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆