iOS: MPMusicPlayerControllerPlaybackStateDidChangeNotification called multiple times on certain devices

前提是你 提交于 2019-12-05 14:29:46
pgkelley

I think this is the same bug reported here:

Getting wrong playback state in MP Music Player Controller in ios 5

I posted a workaround for the bug in that question.

You can check real playback state using currentPlaybackRate property. MPMusicPlaybackStatePaused must match rate 0.0. An example how can it implemented is shown below...

- (void)musicPlayerControllerPlaybackStateDidChangeNotification:(NSNotification *)notification {
    float playbackRate = [((MPMusicPlayerController *)notification.object) currentPlaybackRate];
    MPMusicPlaybackState playbackState = (MPMusicPlaybackState)[notification.userInfo[@"MPMusicPlayerControllerPlaybackStateKey"] integerValue];
    switch (playbackState) {
        case MPMusicPlaybackStatePaused:
            if (playbackRate <= .0f) {
                self.playbackState = playbackState;
            }
            break;
        default:
            self.playbackState = playbackState;
            break;
    }
}

Thus it is possible to cut off false pause notification.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!