add 背景音乐锁屏展示app信息

This commit is contained in:
lianxiang 2018-08-24 22:33:42 +08:00
parent 983bb33644
commit a4242fa7b7
2 changed files with 37 additions and 8 deletions

View File

@ -40,7 +40,7 @@
NSURL *vedioUrl = [[NSBundle mainBundle] URLForResource:@"emojizone" withExtension:@"mp4"];
UNNotificationAttachment *vedioAudio = [UNNotificationAttachment attachmentWithIdentifier:@"vedio" URL:vedioUrl options:nil error:nil];
content.attachments = @[attach,attachAudio,vedioAudio];
content.attachments = @[vedioAudio];
// 60s

View File

@ -120,16 +120,18 @@
#pragma mark
-(void)creatBackGroundMusic{
//
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
//
NSError *payerError;
NSURL *musicUrl = [[NSURL alloc] initWithString:[[NSBundle mainBundle] pathForResource:@"pomodoSound" ofType:@"m4a"]] ;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicUrl error:&payerError];
player.numberOfLoops = -1;
_musicPalyer = player;
[[AVAudioSession sharedInstance] setActive:YES error:nil];
//
//[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
}
@ -140,10 +142,10 @@
delegate.isMasking = YES;
[_musicPalyer play];
[self setBackGroundPlayingInfo];
[self setBackGroundPlayingInfo];//
// s
NSTimeInterval timeInterVal = 10;
NSTimeInterval timeInterVal = 58;
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
@ -165,12 +167,39 @@
MPMediaItemArtwork *arwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"MaskTime.png"]];
NSDictionary *dic = @{
MPMediaItemPropertyTitle:@"专辑名字专辑",
MPMediaItemPropertyTitle:@"面膜时间",
MPMediaItemPropertyAlbumArtist:@"专辑专辑专辑专辑",
MPMediaItemPropertyArtist:@"lianxiang",
MPMediaItemPropertyAlbumTitle:@"hahah",
MPMediaItemPropertyGenre:@"???",
MPMediaItemPropertyLyrics:@"歌词",
MPMediaItemPropertyPodcastTitle:@"PodcastTitle",
MPMediaItemPropertyArtwork:arwork
};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dic];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlPlay:
//
//[_musicPalyer play];
break;
case UIEventSubtypeRemoteControlPause:
// [_musicPalyer pause];
break;
default:
NSLog(@"没有处理过这个事件------receivedEvent.subtype==%ld",(long)receivedEvent.subtype);
break;
}
}
}
#pragma mark