我正在尝试使用 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 .
有任何想法吗!?
1 回答
要从Apple Music播放,请使用MPMusicPlayerController.systemMusicPlayer()