add 背景音乐锁屏展示app信息
This commit is contained in:
parent
983bb33644
commit
a4242fa7b7
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
NSURL *vedioUrl = [[NSBundle mainBundle] URLForResource:@"emojizone" withExtension:@"mp4"];
|
NSURL *vedioUrl = [[NSBundle mainBundle] URLForResource:@"emojizone" withExtension:@"mp4"];
|
||||||
UNNotificationAttachment *vedioAudio = [UNNotificationAttachment attachmentWithIdentifier:@"vedio" URL:vedioUrl options:nil error:nil];
|
UNNotificationAttachment *vedioAudio = [UNNotificationAttachment attachmentWithIdentifier:@"vedio" URL:vedioUrl options:nil error:nil];
|
||||||
content.attachments = @[attach,attachAudio,vedioAudio];
|
content.attachments = @[vedioAudio];
|
||||||
|
|
||||||
|
|
||||||
//延迟通知 第一个参数是重复的时间间隔,最小60s,第二个参数是是否重复。
|
//延迟通知 第一个参数是重复的时间间隔,最小60s,第二个参数是是否重复。
|
||||||
|
|
|
||||||
|
|
@ -120,16 +120,18 @@
|
||||||
|
|
||||||
#pragma mark 面膜时间背景音乐
|
#pragma mark 面膜时间背景音乐
|
||||||
-(void)creatBackGroundMusic{
|
-(void)creatBackGroundMusic{
|
||||||
|
|
||||||
//设置后台模式和锁屏模式下依然能够播放
|
|
||||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
|
||||||
[[AVAudioSession sharedInstance] setActive:YES error:nil];
|
|
||||||
//初始化音频播放器
|
//初始化音频播放器
|
||||||
NSError *payerError;
|
NSError *payerError;
|
||||||
NSURL *musicUrl = [[NSURL alloc] initWithString:[[NSBundle mainBundle] pathForResource:@"pomodoSound" ofType:@"m4a"]] ;
|
NSURL *musicUrl = [[NSURL alloc] initWithString:[[NSBundle mainBundle] pathForResource:@"pomodoSound" ofType:@"m4a"]] ;
|
||||||
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicUrl error:&payerError];
|
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicUrl error:&payerError];
|
||||||
player.numberOfLoops = -1;
|
player.numberOfLoops = -1;
|
||||||
_musicPalyer = player;
|
_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;
|
delegate.isMasking = YES;
|
||||||
[_musicPalyer play];
|
[_musicPalyer play];
|
||||||
|
|
||||||
[self setBackGroundPlayingInfo];
|
[self setBackGroundPlayingInfo];//锁屏音频信息
|
||||||
|
|
||||||
//总时间隔 s
|
//总时间隔 s
|
||||||
NSTimeInterval timeInterVal = 10;
|
NSTimeInterval timeInterVal = 58;
|
||||||
|
|
||||||
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
|
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
|
||||||
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
|
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
|
||||||
|
|
@ -165,12 +167,39 @@
|
||||||
|
|
||||||
MPMediaItemArtwork *arwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"MaskTime.png"]];
|
MPMediaItemArtwork *arwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"MaskTime.png"]];
|
||||||
NSDictionary *dic = @{
|
NSDictionary *dic = @{
|
||||||
MPMediaItemPropertyTitle:@"专辑名字专辑",
|
MPMediaItemPropertyTitle:@"面膜时间",
|
||||||
MPMediaItemPropertyAlbumArtist:@"专辑专辑专辑专辑",
|
MPMediaItemPropertyAlbumArtist:@"专辑专辑专辑专辑",
|
||||||
|
MPMediaItemPropertyArtist:@"lianxiang",
|
||||||
|
MPMediaItemPropertyAlbumTitle:@"hahah",
|
||||||
|
MPMediaItemPropertyGenre:@"???",
|
||||||
|
MPMediaItemPropertyLyrics:@"歌词",
|
||||||
|
MPMediaItemPropertyPodcastTitle:@"PodcastTitle",
|
||||||
MPMediaItemPropertyArtwork:arwork
|
MPMediaItemPropertyArtwork:arwork
|
||||||
};
|
};
|
||||||
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dic];
|
[[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 面膜时间结束
|
#pragma mark 面膜时间结束
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue