|
@@ -52,9 +52,15 @@
|
|
|
[self.timer invalidate];
|
|
|
_isBackgroundType = NO;
|
|
|
|
|
|
- // 恢复音频播放
|
|
|
- [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil]; // ok
|
|
|
- [[AVAudioSession sharedInstance] setActive: YES error: nil];
|
|
|
+ // 恢复音频播放 AVAudioSessionCategoryPlayback 可以在开启静音后播放声音 但是 停止后台播放后 [[AVAudioSession sharedInstance] setActive: No error: nil] 后无声音了 AVAudioSessionCategorySoloAmbient 可以 但是开启静音后无声
|
|
|
+
|
|
|
+ //[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
|
|
+ //[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];//ok
|
|
|
+ //[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil]; // ok
|
|
|
+ //[[AVAudioSession sharedInstance] setActive: YES error: nil];
|
|
|
+
|
|
|
+ [[AVAudioSession sharedInstance] setActive:YES error: nil];
|
|
|
+ [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:nil];
|
|
|
|
|
|
}
|
|
|
|
|
@@ -87,8 +93,8 @@
|
|
|
/// 创建音乐播放器
|
|
|
- (void)creatAVAudioSessionObject{
|
|
|
//设置后台模式和锁屏模式下依然能够播放
|
|
|
- [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
|
|
[[AVAudioSession sharedInstance] setActive: YES error: nil];
|
|
|
+ [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
|
|
//初始化音频播放器
|
|
|
NSError *playerError;
|
|
|
NSURL *urlSound = [[NSURL alloc]initWithString:[[NSBundle mainBundle]pathForResource:@"RunInBackground" ofType:@"mp3"]];
|
|
@@ -120,11 +126,8 @@
|
|
|
[self stopPlayAudioSession];
|
|
|
[self.timer invalidate];
|
|
|
|
|
|
-
|
|
|
- //设置后台模式和锁屏模式下依然能够播放
|
|
|
- //[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
|
|
-
|
|
|
- [[AVAudioSession sharedInstance] setActive:NO error: nil];
|
|
|
+ [[AVAudioSession sharedInstance] setActive:NO withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error: nil];
|
|
|
+ //[[AVAudioSession sharedInstance] setActive:NO error: nil];
|
|
|
[[UIApplication sharedApplication] endBackgroundTask:self.backgrounTask];
|
|
|
self.backgrounTask = UIBackgroundTaskInvalid;
|
|
|
}
|