MPMusicPlayerController打破了锁屏控制

时间:2016-05-17 16:50:56

标签: ios avplayer mpmusicplayercontroller mpmediaitem

我正在尝试使用 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 个答案:

答案 0 :(得分:0)

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