diff --git a/Classes/MainScreenWithVideoPreview.m b/Classes/MainScreenWithVideoPreview.m index f4c6859e9..2947b85d0 100644 --- a/Classes/MainScreenWithVideoPreview.m +++ b/Classes/MainScreenWithVideoPreview.m @@ -106,10 +106,23 @@ [session startRunning]; } +-(void) stopPreview:(id) a { + @synchronized (self) { + if (!session.running) + return; + [self.view removeFromSuperview]; + [session stopRunning]; + } +} + -(void) startPreview:(id) a { - [window addSubview:self.view]; - [window sendSubviewToBack:self.view]; - [session startRunning]; + @synchronized (self) { + if (session.running) + return; + [window addSubview:self.view]; + [window sendSubviewToBack:self.view]; + [session startRunning]; + } } @@ -129,13 +142,10 @@ if (show && !session.running) { [self performSelectorInBackground:@selector(startPreview:) withObject:nil]; } else if (!show && session.running) { - [self.view removeFromSuperview]; - [session stopRunning]; + [self performSelectorInBackground:@selector(stopPreview:) withObject:nil]; } } else { - if (session != nil) - [session stopRunning]; - [self.view removeFromSuperview]; + [self stopPreview:nil]; } } diff --git a/Classes/PhoneViewController.m b/Classes/PhoneViewController.m index e39d32ad4..9d1f45a12 100644 --- a/Classes/PhoneViewController.m +++ b/Classes/PhoneViewController.m @@ -135,8 +135,8 @@ [self updateCallAndBackButtons]; } --(void) viewWillDisappear:(BOOL)animated { - [mMainScreenWithVideoPreview showPreview:NO]; +-(void) viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; } @@ -244,7 +244,7 @@ -(void) displayIncomingCall:(LinphoneCall*) call NotificationFromUI:(UIViewController*) viewCtrl forUser:(NSString*) username withDisplayName:(NSString*) displayName { - + [mMainScreenWithVideoPreview showPreview:NO]; if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { // Create a new notification @@ -304,6 +304,7 @@ } -(void) displayCall: (LinphoneCall*) call InProgressFromUI:(UIViewController*) viewCtrl forUser:(NSString*) username withDisplayName:(NSString*) displayName { + [mMainScreenWithVideoPreview showPreview:NO]; if (self.presentedViewController != (UIViewController*)mIncallViewController) { [self presentModalViewController:(UIViewController*)mIncallViewController animated:true]; } @@ -316,6 +317,7 @@ } -(void) displayInCall: (LinphoneCall*) call FromUI:(UIViewController*) viewCtrl forUser:(NSString*) username withDisplayName:(NSString*) displayName { + [mMainScreenWithVideoPreview showPreview:NO]; if (self.presentedViewController != (UIViewController*)mIncallViewController && (call == 0x0 || linphone_call_get_dir(call)==LinphoneCallIncoming)){ [self presentModalViewController:(UIViewController*)mIncallViewController animated:true]; @@ -336,6 +338,7 @@ -(void) displayVideoCall:(LinphoneCall*) call FromUI:(UIViewController*) viewCtrl forUser:(NSString*) username withDisplayName:(NSString*) displayName { + [mMainScreenWithVideoPreview showPreview:NO]; [mIncallViewController displayVideoCall:call FromUI:viewCtrl forUser:username withDisplayName:displayName];