Apple Music Songs - MPMusicPlayerController提供错误的playbackState

时间:2016-04-13 12:49:55

标签: ios mpmusicplayercontroller apple-music

正如Apple在 iOS 9.3 中所说,我们可以Access Apple Music Library。我是通过MPMusicPlayerController从我的应用程序中播放它。

我的播放状态错误了。对于Ex。如果歌曲继续播放 - 那么它应该返回状态MPMusicPlaybackStatePlaying但是获取其他枚举值。我的代码是

 if ([[MPMusicPlayerController systemMusicPlayer] playbackState]==MPMusicPlaybackStatePlaying)
            {
            }
            else
            {
 NSLog(@"playbackState %ld",(long)[[MPMusicPlayerController systemMusicPlayer] playbackState]);
             }

正如苹果说here我们有以下可能的价值 -

Values for the playbackState property.
Declaration

Objective-C

enum {
   MPMusicPlaybackStateStopped,
   MPMusicPlaybackStatePlaying,
   MPMusicPlaybackStatePaused,
   MPMusicPlaybackStateInterrupted,
   MPMusicPlaybackStateSeekingForward,
   MPMusicPlaybackStateSeekingBackward 
};
typedef NSInteger MPMusicPlaybackState;

我如何获得当前播放歌曲的正确状态。任何想法,如果我弄错了,请告诉我。感谢

2 个答案:

答案 0 :(得分:0)

我也遇到过这个问题。因此,解决方法是:每隔n秒检查[[MPMusicPlayerController systemMusicPlayer] currentPlaybackRate]属性。 1对应于"播放"和0到"暂停" (或停止)。

答案 1 :(得分:0)

这太疯狂了,但这可行:

_ = systemMusicPlayer.currentPlaybackRate        
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
    print(self?.systemMusicPlayer.playbackState)
}