iOS 设置锁屏界面的信息

2017-06-30  本文已影响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;

}

}

上一篇 下一篇

猜你喜欢

热点阅读