2

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

Anupam Mishra
  • 3,408
  • 5
  • 35
  • 63

2 Answers2

1

It is insane but this works:

_ = systemMusicPlayer.currentPlaybackRate        
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
    print(self?.systemMusicPlayer.playbackState)
}
Foti Dim
  • 1,303
  • 13
  • 19
0

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).

newenglander
  • 2,019
  • 24
  • 55
gareg
  • 64
  • 3