Search code examples
iosobjective-ciphonegpuimage

How to manage GPUImage movieFile Processing in background?


I have implemented GPUImage library to apply filters in existing videos, Now issue is that the application is crash when I lock device, I Have also set BOOL variable to get application current state, Bun unfortunately resignActive call after application crash. The crash happen in this line of code.

[self.context presentRenderbuffer:GL_RENDERBUFFER];

Can you please suggest me what is best way to deal with this.


Solution

  • -(void)viewWillAppear:(BOOL)animated{
        [[NSNotificationCenter defaultCenter]addObserver:self
                                                selector:@selector(EnterBackground:)
                                                    name:UIApplicationWillResignActiveNotification
                                                  object:nil];
    
        [[NSNotificationCenter defaultCenter]addObserver:self
                                                selector:@selector(DidBecomeActive:)
                                                    name:UIApplicationDidBecomeActiveNotification
                                                  object:nil];
    
    }
    - (void)EnterBackground:(NSNotification*)notification{
        NSLog(@"Enter in background");
            [self.movieFile endProcessing];
            [self.filter removeAllTargets];
            [self.movieFile removeAllTargets];
    }
    
    - (void)DidBecomeActive:(NSNotification*)notification{
        [_movieFile startProcessing];
    }
    

    Don't forget to remove observer in viewWillDisappear