Fix sound problems
MODIFY
MatrixKit/Controllers/MXKCallViewController.m
MatrixKit/Controllers/MXKCallViewController.m
#import "MXKCallViewController.h"
+#import <MatrixSDK/MXCallKitAdapter.h>
+
#import "MXKAlert.h"
+#import "MXKAppSettings.h"
#import "MXMediaManager.h"
#import "MXKSoundPlayer.h"
#import "MXKTools.h"
@@ -136,6 +139,16 @@ NSString *const kMXKCallViewControllerBackToAppNotification = @"kMXKCallViewCont
// Refresh call information
self.mxCall = mxCall;
+
+ // Listen to AVAudioSession activation notification if CallKit is available and enabled
+ BOOL isCallKitAvailable = [MXCallKitAdapter callKitAvailable] && [MXKAppSettings standardAppSettings].isCallKitEnabled;
+ if (isCallKitAvailable)
+ {
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(handleAudioSessionActivationNotification)
+ name:kMXCallKitAdapterAudioSessionDidActive
+ object:nil];
+ }
}
- (void)didReceiveMemoryWarning
@@ -145,6 +158,7 @@ NSString *const kMXKCallViewControllerBackToAppNotification = @"kMXKCallViewCont
- (void)dealloc
{
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:kMXCallKitAdapterAudioSessionDidActive object:nil];
}
- (void)viewWillAppear:(BOOL)animated
@@ -533,9 +547,16 @@ NSString *const kMXKCallViewControllerBackToAppNotification = @"kMXKCallViewCont
[localPreviewActivityView startAnimating];
break;
case MXCallStateCreateOffer:
+ {
+ BOOL isCallKitAvailable = [MXCallKitAdapter callKitAvailable] && [MXKAppSettings standardAppSettings].isCallKitEnabled;
+ if (!isCallKitAvailable)
+ {
self.isRinging = YES;
+ }
+
callStatusLabel.text = [NSBundle mxk_localizedStringForKey:@"call_ring"];
break;
+ }
case MXCallStateRinging:
self.isRinging = YES;
if (call.isVideoCall)
@@ -597,6 +618,9 @@ NSString *const kMXKCallViewControllerBackToAppNotification = @"kMXKCallViewCont
else
{
[[MXKSoundPlayer sharedInstance] stopPlaying];
+
+ // Release the audio session to allow resuming of background music app
+ [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
}
// Except in case of call error, quit the screen right now
@@ -728,6 +752,15 @@ NSString *const kMXKCallViewControllerBackToAppNotification = @"kMXKCallViewCont
return nil;
}
+- (void)handleAudioSessionActivationNotification
+{
+ // It's only relevant for outgoing calls which aren't in connected state
+ if (self.mxCall.state >= MXCallStateCreateOffer && self.mxCall.state != MXCallStateConnected && self.mxCall.state != MXCallStateEnded)
+ {
+ self.isRinging = YES;
+ }
+}
+
#pragma mark - UI methods
- (void)updateLocalPreviewLayout

Fix sound problems