正如 Apple 在 iOS 9.3 中所说,我们可以 Access Apple Music Library .我正在通过 MPMusicPlayerController 从我的应用程序中播放它。
我得到了错误的播放状态。对于前。如果歌曲继续播放 - 所以它应该返回状态 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;
如何获得当前播放歌曲的正确状态。任何想法,如果我弄错了什么,请告诉我。谢谢
最佳答案
这很疯狂,但这个有效:
_ = systemMusicPlayer.currentPlaybackRate
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
print(self?.systemMusicPlayer.playbackState)
}
关于ios - Apple Music Songs - MPMusicPlayerController 提供错误的播放状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36598942/