美文网首页
iOS 设置锁屏界面的信息

iOS 设置锁屏界面的信息

作者: 清蘂翅膀的技术 | 来源:发表于2017-06-30 13:41 被阅读0次

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

}

}

相关文章

网友评论

      本文标题:iOS 设置锁屏界面的信息

      本文链接:https://www.haomeiwen.com/subject/cnnbcxtx.html