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
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).
It is insane but this works:
_ = systemMusicPlayer.currentPlaybackRate
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
print(self?.systemMusicPlayer.playbackState)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.