Pārlūkot izejas kodu

1.后台运行只有30秒的bug修复

huangxiaodong 1 gadu atpakaļ
vecāks
revīzija
9ddd260ffb

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

@@ -97,8 +97,12 @@
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
    //初始化音频播放器
    NSError *playerError;
-   NSURL *urlSound = [[NSURL alloc]initWithString:[[NSBundle mainBundle]pathForResource:@"RunInBackground" ofType:@"mp3"]];
-   _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlSound error:&playerError];
+    NSString*pathStr = [[NSBundle mainBundle] pathForResource:@"RunInBackground" ofType:@"mp3"];
+    
+    NSURL *urlSound11 = [[NSURL alloc] initFileURLWithPath:pathStr];
+   // HLog(@"%@---%@",pathStr,urlSound11);
+   //NSURL *urlSound = [[NSURL alloc]initWithString:pathStr];
+   _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlSound11 error:&playerError];
    _audioPlayer.numberOfLoops = -1;//无限播放
    //_audioPlayer.volume = 0;
 }
@@ -135,13 +139,13 @@
 #pragma mark - 定时器设置判断后台保活时间,如果将要被后台杀死,重新唤醒
 - (void)applyToSystemForMoreTime {
     //HLog(@"我还在后台运行 哈哈");
-    if ([UIApplication sharedApplication].backgroundTimeRemaining < 30.0) {//如果剩余时间小于30秒
-        [[UIApplication sharedApplication] endBackgroundTask:self.backgrounTask];
-        self.backgrounTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
-            [[UIApplication sharedApplication] endBackgroundTask:self.backgrounTask];
-            self.backgrounTask = UIBackgroundTaskInvalid;
-        }];
-    }
+//    if ([UIApplication sharedApplication].backgroundTimeRemaining < 20.0) {//如果剩余时间小于30秒
+//        [[UIApplication sharedApplication] endBackgroundTask:self.backgrounTask];
+//        self.backgrounTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
+//            [[UIApplication sharedApplication] endBackgroundTask:self.backgrounTask];
+//            self.backgrounTask = UIBackgroundTaskInvalid;
+//        }];
+//    }
 }