iOS 设置锁屏界面的信息

#pragma mark - 设置锁屏界面的信息

- (void)setupLockScreenInfo

{

// 0.获取当前正在播放的歌曲信息

XMGMusic *playingMusic = [XMGMusicTool playingMusic];

// 1.获取锁屏界面中心

MPNowPlayingInfoCenter *playingInfoCenter = [MPNowPlayingInfoCenter defaultCenter];

// 2.设置展示的信息

NSMutableDictionary *playingInfo = [NSMutableDictionary dictionary];

[playingInfo setObject:playingMusic.name forKey:MPMediaItemPropertyAlbumTitle];

[playingInfo setObject:playingMusic.singer forKey:MPMediaItemPropertyArtist];

MPMediaItemArtwork *artWork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:playingMusic.icon]];

[playingInfo setObject:artWork forKey:MPMediaItemPropertyArtwork];

[playingInfo setObject:@(self.currentPlayer.duration) forKey:MPMediaItemPropertyPlaybackDuration];

playingInfoCenter.nowPlayingInfo = playingInfo;

// 3.让应用程序可以接受远程事件

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

}

// 监听远程事件

- (void)remoteControlReceivedWithEvent:(UIEvent *)event

{

switch (event.subtype) {

case UIEventSubtypeRemoteControlPlay:

case UIEventSubtypeRemoteControlPause:

[self playOrPause];

break;

case UIEventSubtypeRemoteControlNextTrack:

[self next];

break;

case UIEventSubtypeRemoteControlPreviousTrack:

[self previous];

break;

default:

break;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容