2
votes

As Apple said in iOS 9.3 we can Access Apple Music Library. I am playing it from my application by MPMusicPlayerController.

I am getting wrong playbackState. For Ex. If song continue playing - so it should return status MPMusicPlaybackStatePlaying but gettting other enum values. My code is

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

As apple saying here we have following possible vales -

Values for the playbackState property.
Declaration

Objective-C

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

How will I get the correct state of current playing song . Any Idea, If I mistaken something please let me know. Thanks

2

2 Answers

1
votes

It is insane but this works:

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

I've also faced this issue. So the workaround is: every n seconds check the [[MPMusicPlayerController systemMusicPlayer] currentPlaybackRate] property. 1 corresponds to "playing" and 0 to "paused" (or stopped).