MPMusicPlayerController

MPMusicPlayerController

我正在尝试使用 MPMusicPlayerController 播放苹果音乐歌曲,但是无法使锁屏控件正常工作。似乎MPMusicPlayerController重写了 remoteControlReceivedWithEvent 侦听器。

这是我设置控制器的方式:

self.player = [MPMusicPlayerController applicationMusicPlayer];
self.player.repeatMode = MPMusicRepeatModeNone;
self.player.shuffleMode = MPMusicShuffleModeOff;
[self.player beginGeneratingPlaybackNotifications];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.player ];


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleItemChanged:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:self.player ];

然后我播放苹果音乐歌曲:
NSMutableArray *storeIDS = [NSMutableArray arrayWithObjects:anthem.song.apple_id, @"1", nil];

[self.player setQueueWithStoreIDs:storeIDS];
[self.player play];
[self.player setCurrentPlaybackRate:1.0];

作为参考,这是我在didFinishLaunchingWithOptions中设置远程控制侦听器的方式:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

此时,播放器将按要求播放歌曲,但是我无法再接收任何远程控制通知。因为下一首/上一首歌曲已到达列表末尾,所以只需停止它即可。我已经尝试过applicationMusicPlayer以及systemMusicPlayer。我不能使用AVPlayer或AVAudioPlayer,因为它是Apple Music,并且无法获取URL。

有任何想法吗!?

最佳答案

要从Apple Music播放,请使用MPMusicPlayerController.systemMusicPlayer()

10-08 04:25