Fixed issue #139.

Testing has been completed on outgoing calls only. It is recommended that testing is conducted on incoming calls before a commit to upstream.
pull/1/head
Gil Azaria 11 years ago committed by Frederic Jacobs
parent efdda2f073
commit 6951fd1fbe

@ -70,4 +70,4 @@ SPEC CHECKSUMS:
UICKeyChainStore: eef407137f0397e95a3df32cdf05f7e2ddd99647 UICKeyChainStore: eef407137f0397e95a3df32cdf05f7e2ddd99647
UnionFind: 45777a8b6878d3a602af3654cc3a09b87389d356 UnionFind: 45777a8b6878d3a602af3654cc3a09b87389d356
COCOAPODS: 0.34.1 COCOAPODS: 0.34.4

@ -2,6 +2,7 @@
#import "CallProgress.h" #import "CallProgress.h"
#import "CallTermination.h" #import "CallTermination.h"
#import "SoundPlayer.h"
/** /**
* The AppAudioManager is a Singleton object used to control audio settings / updates * The AppAudioManager is a Singleton object used to control audio settings / updates
@ -13,7 +14,7 @@
* which speaker to use or if all sounds should be muted. * which speaker to use or if all sounds should be muted.
**/ **/
@interface AppAudioManager : NSObject @interface AppAudioManager : NSObject <SoundPlayerDelegate>
enum AudioProfile { enum AudioProfile {
AudioProfile_Default, AudioProfile_Default,
@ -37,4 +38,7 @@ enum AudioProfile {
-(BOOL) setAudioEnabled:(BOOL) enable; -(BOOL) setAudioEnabled:(BOOL) enable;
-(void) awake; -(void) awake;
- (void)didCompleteSoundInstanceOfType:(SoundInstanceType)instanceType;
@end @end

@ -28,7 +28,7 @@ AppAudioManager* sharedAppAudioManager;
if( nil == sharedAppAudioManager){ if( nil == sharedAppAudioManager){
sharedAppAudioManager = [AppAudioManager new]; sharedAppAudioManager = [AppAudioManager new];
sharedAppAudioManager.soundPlayer = [SoundPlayer new]; sharedAppAudioManager.soundPlayer = [SoundPlayer new];
[sharedAppAudioManager setAudioEnabled:YES]; [[sharedAppAudioManager soundPlayer] setDelegate:sharedAppAudioManager];
} }
} }
return sharedAppAudioManager; return sharedAppAudioManager;
@ -74,9 +74,11 @@ AppAudioManager* sharedAppAudioManager;
} }
#pragma mark AudioControl; #pragma mark AudioControl;
-(void) respondToProgressChange:(enum CallProgressType) progressType forLocallyInitiatedCall:(BOOL) initiatedLocally { -(void) respondToProgressChange:(enum CallProgressType) progressType
forLocallyInitiatedCall:(BOOL) initiatedLocally {
switch (progressType){ switch (progressType){
case CallProgressType_Connecting: case CallProgressType_Connecting:
[sharedAppAudioManager setAudioEnabled:YES];
[_soundPlayer stopAllAudio]; [_soundPlayer stopAllAudio];
case CallProgressType_Ringing: case CallProgressType_Ringing:
(initiatedLocally) ? [self handleOutboundRing] : [self handleInboundRing]; (initiatedLocally) ? [self handleOutboundRing] : [self handleInboundRing];
@ -106,12 +108,13 @@ AppAudioManager* sharedAppAudioManager;
-(BOOL) shouldErrorSoundBePlayedForCallTerminationType:(enum CallTerminationType) type{ -(BOOL) shouldErrorSoundBePlayedForCallTerminationType:(enum CallTerminationType) type{
[_soundPlayer stopAllAudio]; [_soundPlayer stopAllAudio];
if (CallTerminationType_RejectedLocal) {return NO;} if (type == CallTerminationType_RejectedLocal ||
else if (CallTerminationType_RejectedRemote) {return NO;} type == CallTerminationType_RejectedRemote ||
else if (CallTerminationType_HangupLocal) {return NO;} type == CallTerminationType_HangupLocal ||
else if (CallTerminationType_HangupRemote) {return NO;} type == CallTerminationType_HangupRemote ||
else if (CallTerminationType_RecipientUnavailable) {return NO;} type == CallTerminationType_RecipientUnavailable) {
return NO;
}
return YES; return YES;
} }
@ -174,14 +177,31 @@ AppAudioManager* sharedAppAudioManager;
-(BOOL) setAudioEnabled:(BOOL) enable { -(BOOL) setAudioEnabled:(BOOL) enable {
NSError* e; NSError* e;
[AVAudioSession.sharedInstance setActive:enable error:&e]; if (enable) {
[_soundPlayer awake]; [[AVAudioSession sharedInstance] setActive:enable error:&e];
[_soundPlayer awake];
}
else {
[[AVAudioSession sharedInstance] setActive:enable
withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
error:&e];
}
return ( nil !=e ); return ( nil !=e );
} }
-(void) awake { -(void) awake {
[_soundPlayer awake]; [_soundPlayer awake];
} }
#pragma mark Sound Player Delegate
- (void)didCompleteSoundInstanceOfType:(SoundInstanceType)instanceType {
if (instanceType == SoundInstanceTypeBusySound ||
instanceType == SoundInstanceTypeErrorAlert ||
instanceType == SoundInstanceTypeAlert) {
[sharedAppAudioManager setAudioEnabled:NO];
}
}
@end @end

@ -10,42 +10,49 @@ static NSString* SoundFile_Ringtone =@"r.caf";
@implementation SoundBoard @implementation SoundBoard
+(SoundInstance*) instanceOfInboundRingtone{ +(SoundInstance*) instanceOfInboundRingtone {
SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Ringtone]; SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Ringtone];
[soundInstance setAudioToLoopIndefinitely]; [soundInstance setAudioToLoopIndefinitely];
[soundInstance setInstanceType:SoundInstanceTypeInboundRingtone];
return soundInstance; return soundInstance;
} }
+(SoundInstance*) instanceOfOutboundRingtone{ +(SoundInstance*) instanceOfOutboundRingtone {
SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Outbound]; SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Outbound];
[soundInstance setAudioToLoopIndefinitely]; [soundInstance setAudioToLoopIndefinitely];
[soundInstance setInstanceType:SoundInstanceTypeBusySound];
return soundInstance; return soundInstance;
} }
+(SoundInstance*) instanceOfHandshakeSound { +(SoundInstance*) instanceOfHandshakeSound {
SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Handshake]; SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Handshake];
[soundInstance setAudioToLoopIndefinitely]; [soundInstance setAudioToLoopIndefinitely];
[soundInstance setInstanceType:SoundInstanceTypeHandshakeSound];
return soundInstance; return soundInstance;
} }
+(SoundInstance*) instanceOfCompletedSound { +(SoundInstance*) instanceOfCompletedSound {
SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Completed]; SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Completed];
[soundInstance setInstanceType:SoundInstanceTypeCompletedSound];
return soundInstance; return soundInstance;
} }
+(SoundInstance*) instanceOfBusySound { +(SoundInstance*) instanceOfBusySound {
SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Busy]; SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Busy];
[soundInstance setAudioLoopCount:10]; [soundInstance setAudioLoopCount:10];
[soundInstance setInstanceType:SoundInstanceTypeBusySound];
return soundInstance; return soundInstance;
} }
+(SoundInstance*) instanceOfErrorAlert { +(SoundInstance*) instanceOfErrorAlert {
SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Failure]; SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Failure];
[soundInstance setInstanceType:SoundInstanceTypeErrorAlert];
return soundInstance; return soundInstance;
} }
+(SoundInstance*) instanceOfAlert { +(SoundInstance*) instanceOfAlert {
SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Alert]; SoundInstance* soundInstance = [SoundInstance soundInstanceForFile:SoundFile_Alert];
[soundInstance setInstanceType:SoundInstanceTypeAlert];
return soundInstance; return soundInstance;
} }

@ -6,10 +6,26 @@
@interface SoundInstance : NSObject <AVAudioPlayerDelegate> @interface SoundInstance : NSObject <AVAudioPlayerDelegate>
typedef enum {
SoundInstanceTypeNothing,
SoundInstanceTypeInboundRingtone,
SoundInstanceTypeOutboundRingtone,
SoundInstanceTypeHandshakeSound,
SoundInstanceTypeCompletedSound,
SoundInstanceTypeBusySound,
SoundInstanceTypeErrorAlert,
SoundInstanceTypeAlert
} SoundInstanceType;
@property (nonatomic) SoundInstanceType instanceType;
+(SoundInstance*) soundInstanceForFile:(NSString*) audioFile; +(SoundInstance*) soundInstanceForFile:(NSString*) audioFile;
-(NSString*) getId; -(NSString*) getId;
-(void) setAudioToLoopIndefinitely; -(void) setAudioToLoopIndefinitely;
-(void) setAudioLoopCount:(NSInteger) loopCount; -(void) setAudioLoopCount:(NSInteger) loopCount;
-(void) setCompeletionBlock:(void (^)(SoundInstance*)) block; -(void) setCompeletionBlock:(void (^)(SoundInstance*)) block;
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player
successfully:(BOOL)flag;
@end @end

@ -5,6 +5,7 @@
} }
@property (retain) AVAudioPlayer *audioPlayer; @property (retain) AVAudioPlayer *audioPlayer;
@end @end
@implementation SoundInstance @implementation SoundInstance
@ -26,6 +27,7 @@
-(void) stop { -(void) stop {
[self.audioPlayer stop]; [self.audioPlayer stop];
[self audioPlayerDidFinishPlaying:self.audioPlayer successfully:YES];
} }
-(void) setAudioToLoopIndefinitely { -(void) setAudioToLoopIndefinitely {
@ -36,6 +38,13 @@
self.audioPlayer.numberOfLoops = loopCount; self.audioPlayer.numberOfLoops = loopCount;
} }
- (SoundInstanceType)instanceType {
if (!_instanceType) {
_instanceType = SoundInstanceTypeNothing;
}
return _instanceType;
}
+(NSURL*) urlToFile:(NSString*) file { +(NSURL*) urlToFile:(NSString*) file {
return [NSURL fileURLWithPath: return [NSURL fileURLWithPath:
[NSString stringWithFormat:@"%@/%@", NSBundle.mainBundle.resourcePath,file]]; [NSString stringWithFormat:@"%@/%@", NSBundle.mainBundle.resourcePath,file]];
@ -50,7 +59,6 @@
return audioPlayer; return audioPlayer;
} }
-(void) setCompeletionBlock:(void (^)(SoundInstance* )) block { -(void) setCompeletionBlock:(void (^)(SoundInstance* )) block {
completionBlock = block; completionBlock = block;
} }

@ -7,12 +7,23 @@
* sound is ignored. Multiple different sound instances can be played concurrently. * sound is ignored. Multiple different sound instances can be played concurrently.
*/ */
@protocol SoundPlayerDelegate;
@interface SoundPlayer : NSObject @interface SoundPlayer : NSObject
@property (strong, nonatomic) id<SoundPlayerDelegate> delegate;
-(void) playSound:(SoundInstance*) player; -(void) playSound:(SoundInstance*) player;
-(void) stopSound:(SoundInstance*) player; -(void) stopSound:(SoundInstance*) player;
-(void) stopAllAudio; -(void) stopAllAudio;
-(void) awake; -(void) awake;
@end @end
@protocol SoundPlayerDelegate <NSObject>
@optional
- (void)didCompleteSoundInstanceOfType:(SoundInstanceType)instanceType;
@end

@ -22,6 +22,9 @@ NSMutableDictionary* currentActiveAudioPlayers;
@synchronized(currentActiveAudioPlayers){ @synchronized(currentActiveAudioPlayers){
[sound setCompeletionBlock:^(SoundInstance* soundInst) { [sound setCompeletionBlock:^(SoundInstance* soundInst) {
[self removeSoundFromManifest:soundInst]; [self removeSoundFromManifest:soundInst];
if (self.delegate) {
[self.delegate didCompleteSoundInstanceOfType:soundInst.instanceType];
}
}]; }];
[currentActiveAudioPlayers setValue:sound forKey:sound.getId]; [currentActiveAudioPlayers setValue:sound forKey:sound.getId];
} }

@ -7,8 +7,6 @@
#import "CallAudioManager.h" #import "CallAudioManager.h"
#import "PhoneManager.h" #import "PhoneManager.h"
#import <MediaPlayer/MPMusicPlayerController.h>
#define BUTTON_BORDER_WIDTH 1.0f #define BUTTON_BORDER_WIDTH 1.0f
#define CONTACT_IMAGE_BORDER_WIDTH 2.0f #define CONTACT_IMAGE_BORDER_WIDTH 2.0f
#define RINGING_ROTATION_DURATION 0.375f #define RINGING_ROTATION_DURATION 0.375f
@ -24,7 +22,6 @@ static NSInteger connectingFlashCounter = 0;
@interface InCallViewController () { @interface InCallViewController () {
BOOL _isMusicPaused;
CallAudioManager *_callAudioManager; CallAudioManager *_callAudioManager;
NSTimer *_connectingFlashTimer; NSTimer *_connectingFlashTimer;
NSTimer *_ringingAnimationTimer; NSTimer *_ringingAnimationTimer;
@ -47,7 +44,6 @@ static NSInteger connectingFlashCounter = 0;
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self showCallState]; [self showCallState];
[self pauseMusicIfPlaying];
[self setupButtonBorders]; [self setupButtonBorders];
[self localizeButtons]; [self localizeButtons];
[UIDevice.currentDevice setProximityMonitoringEnabled:YES]; [UIDevice.currentDevice setProximityMonitoringEnabled:YES];
@ -75,13 +71,6 @@ static NSInteger connectingFlashCounter = 0;
[self handleIncomingDetails]; [self handleIncomingDetails];
} }
- (void)pauseMusicIfPlaying {
if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying) {
_isMusicPaused = YES;
[[MPMusicPlayerController iPodMusicPlayer] pause];
}
}
- (void)startConnectingFlashAnimation { - (void)startConnectingFlashAnimation {
if(!_ringingAnimationTimer.isValid){ if(!_ringingAnimationTimer.isValid){
_connectingFlashTimer = [NSTimer scheduledTimerWithTimeInterval:CONNECTING_FLASH_DURATION _connectingFlashTimer = [NSTimer scheduledTimerWithTimeInterval:CONNECTING_FLASH_DURATION
@ -207,7 +196,7 @@ static NSInteger connectingFlashCounter = 0;
BOOL showAcceptRejectButtons = !_callState.initiatedLocally && [latestProgress type] <= CallProgressType_Ringing; BOOL showAcceptRejectButtons = !_callState.initiatedLocally && [latestProgress type] <= CallProgressType_Ringing;
[self displayAcceptRejectButtons:showAcceptRejectButtons]; [self displayAcceptRejectButtons:showAcceptRejectButtons];
[AppAudioManager.sharedInstance respondToProgressChange:[latestProgress type] [AppAudioManager.sharedInstance respondToProgressChange:[latestProgress type]
forLocallyInitiatedCall:_callState.initiatedLocally]; forLocallyInitiatedCall:_callState.initiatedLocally];
if ([latestProgress type] == CallProgressType_Ringing) { if ([latestProgress type] == CallProgressType_Ringing) {
[self startRingingAnimation]; [self startRingingAnimation];
@ -228,10 +217,6 @@ static NSInteger connectingFlashCounter = 0;
[Environment.phoneManager hangupOrDenyCall]; [Environment.phoneManager hangupOrDenyCall];
[self dismissViewWithOptionalDelay: [termination type] != CallTerminationType_ReplacedByNext ]; [self dismissViewWithOptionalDelay: [termination type] != CallTerminationType_ReplacedByNext ];
if (_isMusicPaused) {
[[MPMusicPlayerController iPodMusicPlayer] play];
}
} }
- (void)endCallTapped { - (void)endCallTapped {

Loading…
Cancel
Save