Skip to content

Commit

Permalink
fix #102
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiulin committed Apr 12, 2020
1 parent 00d5055 commit c03e7cc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ios/RTCSystemSetting.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @interface RCTSystemSetting()

@implementation RCTSystemSetting {
bool hasListeners;
long skipSetVolumeCount;
#ifdef BLUETOOTH
CBCentralManager *cb;
#endif
Expand Down Expand Up @@ -57,6 +58,7 @@ -(instancetype)init{
}

-(void)initVolumeView{
skipSetVolumeCount = 0;
volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(-[UIScreen mainScreen].bounds.size.width, 0, 0, 0)];
[self showVolumeUI:YES];
for (UIView* view in volumeView.subviews) {
Expand Down Expand Up @@ -96,6 +98,7 @@ +(BOOL)requiresMainQueueSetup{
}

RCT_EXPORT_METHOD(setVolume:(float)val config:(NSDictionary *)config){
skipSetVolumeCount++;
dispatch_sync(dispatch_get_main_queue(), ^{
id showUI = [config objectForKey:@"showUI"];
[self showVolumeUI:(showUI != nil && [showUI boolValue])];
Expand Down Expand Up @@ -216,10 +219,13 @@ -(void)stopObserving {
}

-(void)volumeChanged:(NSNotification *)notification{
if(hasListeners){
if(skipSetVolumeCount == 0 && hasListeners){
float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
[self sendEventWithName:@"EventVolume" body:@{@"value": [NSNumber numberWithFloat:volume]}];
}
if(skipSetVolumeCount > 0){
skipSetVolumeCount--;
}
}

#ifdef BLUETOOTH
Expand Down

0 comments on commit c03e7cc

Please sign in to comment.