Add parameter to stopPlaying method
MODIFY
MatrixKit/Controllers/MXKCallViewController.m
MatrixKit/Controllers/MXKCallViewController.m
@@ -425,7 +425,7 @@ NSString *const kMXKCallViewControllerBackToAppNotification = @"kMXKCallViewCont
}
else
{
- [[MXKSoundPlayer sharedInstance] stopPlaying];
+ [[MXKSoundPlayer sharedInstance] stopPlayingWithAudioSessionDeactivation:NO];
}
_isRinging = isRinging;
@@ -548,6 +548,10 @@ NSString *const kMXKCallViewControllerBackToAppNotification = @"kMXKCallViewCont
break;
case MXCallStateCreateOffer:
{
+ // When CallKit is enabled and we have an outgoing call, we need to start playing ringback sound
+ // only after AVAudioSession will be activated by the system otherwise the sound will be gone.
+ // We always receive signal about MXCallStateCreateOffer earlier than the system activates AVAudioSession
+ // so we start playing ringback sound only on AVAudioSession activation in handleAudioSessionActivationNotification
BOOL isCallKitAvailable = [MXCallKitAdapter callKitAvailable] && [MXKAppSettings standardAppSettings].isCallKitEnabled;
if (!isCallKitAvailable)
{
@@ -617,10 +621,7 @@ 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];
+ [[MXKSoundPlayer sharedInstance] stopPlayingWithAudioSessionDeactivation:YES];
}
// Except in case of call error, quit the screen right now

MODIFY
MatrixKit/Utils/MXKSoundPlayer.h
MatrixKit/Utils/MXKSoundPlayer.h
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)new NS_UNAVAILABLE;
- (void)playSoundAt:(NSURL *)url repeat:(BOOL)repeat vibrate:(BOOL)vibrate routeToBuiltInReceiver:(BOOL)useBuiltInReceiver;
-- (void)stopPlaying;
+- (void)stopPlayingWithAudioSessionDeactivation:(BOOL)deactivateAudioSession;
- (void)vibrateWithRepeat:(BOOL)repeat;
- (void)stopVibrating;

MODIFY
MatrixKit/Utils/MXKSoundPlayer.m
MatrixKit/Utils/MXKSoundPlayer.m
@@ -45,7 +45,7 @@ static const NSTimeInterval kVibrationInterval = 1.24875;
{
if (self.audioPlayer)
{
- [self stopPlaying];
+ [self stopPlayingWithAudioSessionDeactivation:NO];
}
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
@@ -68,12 +68,18 @@ static const NSTimeInterval kVibrationInterval = 1.24875;
[self.audioPlayer play];
}
-- (void)stopPlaying
+- (void)stopPlayingWithAudioSessionDeactivation:(BOOL)deactivateAudioSession;
{
if (self.audioPlayer)
{
[self.audioPlayer stop];
self.audioPlayer = nil;
+
+ if (deactivateAudioSession)
+ {
+ // Release the audio session to allow resuming of background music app
+ [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
+ }
}
if (self.isVibrating)

Add parameter to stopPlaying method