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

查看:108
本文介绍了在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];
 }


推荐答案

我也报告了这个bug到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天全站免登陆