[英]Apple Music Songs - MPMusicPlayerController giving wrong playbackState
As Apple said in iOS 9.3 we can Access Apple Music Library . 如Apple在iOS 9.3中所说,我们可以访问Apple Music Library 。 I am playing it from my application by MPMusicPlayerController
. 我正在通过MPMusicPlayerController
从我的应用程序中播放它。
I am getting wrong playbackState. 我在播放状态错误。 For Ex. 对于前 If song continue playing - so it should return status MPMusicPlaybackStatePlaying
but gettting other enum values. 如果歌曲继续播放-因此它应该返回状态MPMusicPlaybackStatePlaying
但获取其他枚举值。 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. 因此,解决方法是:每隔n秒检查一次[[MPMusicPlayerController systemMusicPlayer] currentPlaybackRate]
属性。 1 corresponds to "playing" and 0 to "paused" (or stopped). 1对应于“播放”,0对应于“暂停”(或停止)。
It is insane but this works: 这太疯狂了,但这可以起作用:
_ = systemMusicPlayer.currentPlaybackRate
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
print(self?.systemMusicPlayer.playbackState)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.