MPMusicPlayerController打破了锁屏控制 [英] MPMusicPlayerController breaks lock screen controls

查看:159
本文介绍了MPMusicPlayerController打破了锁屏控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MPMusicPlayerController 来播放苹果音乐歌曲,但我无法让锁屏控件正常工作。好像MPMusicPlayerController重写了 remoteControlReceivedWithEvent 监听器。

I'm attempting to use MPMusicPlayerController to play apple music songs, but I can't get the lock screen controls to work. It seems as though MPMusicPlayerController overridess the remoteControlReceivedWithEvent listener.

以下是我设置控制器的方法:

Here is how I set up my controller:

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 ];

然后我播放苹果音乐歌曲:

Then I play apple music songs:

NSMutableArray *storeIDS = [NSMutableArray arrayWithObjects:anthem.song.apple_id, @"1", nil];

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

作为参考,以下是我在didFinishLaunchingWithOptions中设置遥控器监听器的方法:

For reference, here is how I setup the remote control listener in didFinishLaunchingWithOptions:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

此时,播放器按要求播放歌曲,但我无法再接收任何遥控器通知。点击下一个/上一个只是停止歌曲,因为它已到达列表的末尾。我尝试过使用applicationMusicPlayer以及systemMusicPlayer。我不能使用AVPlayer或AVAudioPlayer,因为它是Apple Music而我无法获得流式传输的URL。

At this point, the player plays the song as requested, but I can no longer receive any remote control notifications. Hitting next/prev simply stop the song since it has reached the end of the list. I've tried with the applicationMusicPlayer as well as the systemMusicPlayer. I can't use AVPlayer or AVAudioPlayer because it's Apple Music and I cannot get the URL to stream.

任何想法!?

推荐答案

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

To play from Apple Music use MPMusicPlayerController.systemMusicPlayer()

这篇关于MPMusicPlayerController打破了锁屏控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆