mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-03 20:46:28 +00:00
fix speaker button behavior
This commit is contained in:
parent
a3d87bedaf
commit
df5635e506
1 changed files with 28 additions and 7 deletions
|
|
@ -19,9 +19,27 @@
|
|||
|
||||
#import "UISpeakerButton.h"
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#include "linphonecore.h"
|
||||
|
||||
@implementation UISpeakerButton
|
||||
|
||||
static void audioRouteChangeListenerCallback (
|
||||
void *inUserData, // 1
|
||||
AudioSessionPropertyID inPropertyID, // 2
|
||||
UInt32 inPropertyValueSize, // 3
|
||||
const void *inPropertyValue // 4
|
||||
) {
|
||||
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return; // 5
|
||||
[(UISpeakerButton*)inUserData reset];
|
||||
|
||||
}
|
||||
|
||||
-(void) initWithOnImage:(UIImage*) onImage offImage:(UIImage*) offImage {
|
||||
[super initWithOnImage:onImage offImage:offImage];
|
||||
AudioSessionPropertyID routeChangeID = kAudioSessionProperty_AudioRouteChange;
|
||||
AudioSessionAddPropertyListener(routeChangeID, audioRouteChangeListenerCallback, self);
|
||||
}
|
||||
|
||||
|
||||
-(void) onOn {
|
||||
//redirect audio to speaker
|
||||
|
|
@ -38,13 +56,16 @@
|
|||
, &audioRouteOverride);
|
||||
}
|
||||
-(bool) isInitialStateOn {
|
||||
UInt32 audioRouteOverride;
|
||||
UInt32 size = sizeof (audioRouteOverride);
|
||||
AudioSessionGetProperty (kAudioSessionProperty_OverrideAudioRoute
|
||||
, &size
|
||||
, (void*)(&audioRouteOverride));
|
||||
return kAudioSessionOverrideAudioRoute_Speaker == audioRouteOverride;
|
||||
|
||||
CFStringRef lNewRoute=CFSTR("Unknown");
|
||||
UInt32 lNewRouteSize = sizeof(lNewRoute);
|
||||
OSStatus lStatus = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute
|
||||
,&lNewRouteSize
|
||||
,&lNewRoute);
|
||||
if (!lStatus && CFStringGetLength(lNewRoute) > 0) {
|
||||
ms_message("Current audio route is [%s]",CFStringGetCStringPtr(lNewRoute, kCFStringEncodingUTF8));
|
||||
return (kCFCompareEqualTo == CFStringCompare (lNewRoute,CFSTR("Speaker"),0));
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue