Przeglądaj źródła

1.修改后台保活逻辑会把云机的云盘播放停掉----后台保护逻辑要重新测试

huangxiaodong 1 rok temu
rodzic
commit
bd1e073050

+ 10 - 5
创维盒子/双子星云手机/Vendor/BackgroundKeepAlive/AudioSessionObject.m

@@ -35,7 +35,6 @@
     if (self) {
         [self addNoti];
         [self creatAVAudioSessionObject];
-        _isBackgroundType = YES;
     }
     return self;
 }
@@ -82,31 +81,37 @@
    NSURL *urlSound = [[NSURL alloc]initWithString:[[NSBundle mainBundle]pathForResource:@"RunInBackground" ofType:@"mp3"]];
    _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlSound error:&playerError];
    _audioPlayer.numberOfLoops = -1;//无限播放
-   _audioPlayer.volume = 0;
+   //_audioPlayer.volume = 0;
 }
 
 /// 开始播放声音
 - (void)startPlayAudioSession{
     NSLog(@"%@ startPlayAudioSession",NSStringFromClass([self class]));
-   [_audioPlayer play];
+   //[_audioPlayer play];
+    _isBackgroundType = YES;
 }
 
 /// 停止播放声音
 - (void)stopPlayAudioSession{
     NSLog(@"%@ stopPlayAudioSession",NSStringFromClass([self class]));
-   [_audioPlayer stop];
+   //[_audioPlayer stop];
     _isBackgroundType = NO;
 }
 
  - (void)stopBackgroundActiveFun
 {
+    if(!_isBackgroundType){
+        return;
+    }
+    
     [self stopPlayAudioSession];
     [self.timer invalidate];
     [[UIApplication sharedApplication] endBackgroundTask:self.self.backgrounTask];
     
     //设置后台模式和锁屏模式下依然能够播放
     //[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
-    [[AVAudioSession sharedInstance] setActive: NO error: nil];
+    
+    //[[AVAudioSession sharedInstance] setActive: NO error: nil];
 }
  
 #pragma mark - 定时器设置判断后台保活时间,如果将要被后台杀死,重新唤醒