Skip to content

Commit

Permalink
v1.7.6: iOS: Capture underlying AVAudioEngine error codes (if any err…
Browse files Browse the repository at this point in the history
…or) in SamplePlayer.play()
  • Loading branch information
birdofpreyru committed Sep 26, 2023
1 parent 0926982 commit a7b8300
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PODS:
- boost (1.76.0)
- CocoaAsyncSocket (7.6.5)
- DoubleConversion (1.1.6)
- dr-pogodin-react-native-audio (1.7.5):
- dr-pogodin-react-native-audio (1.7.6):
- hermes-engine
- RCT-Folly (= 2021.07.22.00)
- RCTRequired
Expand Down Expand Up @@ -1297,7 +1297,7 @@ SPEC CHECKSUMS:
boost: 57d2868c099736d80fcd648bf211b4431e51a558
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
dr-pogodin-react-native-audio: ed6a831e40143f4ad56db80e318b6a35fff6750e
dr-pogodin-react-native-audio: f47c8dcaac38c0891ca3fcdd0d051cc27b4ebb18
dr-pogodin-react-native-fs: bb2051cf55bd125d705d5fa227439e091ac91bf1
FBLazyVector: 71803c074f6325f10b5ec891c443b6bbabef0ca7
Flipper: 6edb735e6c3e332975d1b17956bcc584eccf5818
Expand Down
8 changes: 4 additions & 4 deletions example/ios/ReactNativeAudioExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@
"$(inherited)",
"-Wl",
"-ld_classic",
" ",
"-Wl -ld_classic ",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -736,8 +736,8 @@
"$(inherited)",
"-Wl",
"-ld_classic",
" ",
"-Wl -ld_classic ",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down
2 changes: 1 addition & 1 deletion ios/RNASamplePlayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (void) play:(RCTPromiseResolveBlock)resolve
NSError *error;
AVAudioEngine *engine = player.engine;
if (engine.running != YES && [engine startAndReturnError:&error] != YES) {
[[RNAudioException INTERNAL_ERROR:error.localizedDescription] reject:reject];
[[RNAudioException fromError:error] reject:reject];
return;
}
[player play];
Expand Down
7 changes: 6 additions & 1 deletion ios/RNAudioException.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ typedef void (^OnError)(NSString *error);

@interface RNAudioException : NSException
- (id) initWithName:(NSString*)name details:(NSString*)details;

- (id) initWithName:(NSString*)name
details:(NSString*)details
code:(NSInteger)code
userInfo:(NSDictionary<NSErrorUserInfoKey,id>*)userInfo;

- (NSError*) error;
- (RNAudioException*) log;
- (RNAudioException*) reject:(RCTPromiseRejectBlock)reject;
Expand All @@ -23,7 +26,9 @@ typedef void (^OnError)(NSString *error);
+ (RNAudioException*) name:(NSString*)name;
+ (RNAudioException*) name:(NSString*)name details:(NSString*)details;

+ (RNAudioException*) INTERNAL_ERROR:(NSString*)details;
+ (RNAudioException*) INTERNAL_ERROR:(NSInteger)code
details:(NSString*)details;

+ (RNAudioException*) OPERATION_FAILED:(NSString*)details;
+ (RNAudioException*) UNKNOWN_PLAYER_ID:(RCTPromiseRejectBlock)reject;
+ (RNAudioException*) UNKNOWN_SAMPLE_NAME:(RCTPromiseRejectBlock)reject;
Expand Down
14 changes: 10 additions & 4 deletions ios/RNAudioException.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ - (id) initWithName:(NSString *)name details:(NSString *)details
}

- (id) initWithName:(NSString*)name
details:(NSString*)details
userInfo:(NSDictionary<NSErrorUserInfoKey, id>*)userInfo
details:(NSString*)details
code:(NSInteger)code
userInfo:(NSDictionary<NSErrorUserInfoKey, id>*)userInfo
{
self->_code = code;
self = [super initWithName:name reason:details userInfo:userInfo];
return self;
}
Expand Down Expand Up @@ -57,6 +59,7 @@ + (RNAudioException*) fromError:(NSError*)error
return [[RNAudioException alloc]
initWithName:error.domain
details:error.localizedDescription
code:error.code
userInfo:error.userInfo];
}

Expand Down Expand Up @@ -87,11 +90,14 @@ + (RNAudioException*) name:(NSString*)name details:(NSString*)details
return [[RNAudioException alloc] initWithName:name details:details];
}

+ (RNAudioException*) INTERNAL_ERROR:(NSString*)details
+ (RNAudioException*) INTERNAL_ERROR:(NSInteger)code
details:(NSString *)details
{
return [[RNAudioException alloc]
initWithName:@"Internal error"
details:details];
details:details
code:code
userInfo:nil];
}

+ (RNAudioException*) OPERATION_FAILED:(NSString *)details
Expand Down
3 changes: 2 additions & 1 deletion ios/ReactNativeAudio.mm
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ - (dispatch_queue_t)methodQueue
{
NSNumber *id = [NSNumber numberWithDouble:playerId];
if (samplePlayers[id] != nil) {
[[RNAudioException INTERNAL_ERROR:@"Sample player ID is occupied"]
[[RNAudioException INTERNAL_ERROR:0
details:@"Sample player ID is occupied"]
reject:reject];
return;
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dr.pogodin/react-native-audio",
"version": "1.7.5",
"version": "1.7.6",
"description": "React Native: access to the audio input stream",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit a7b8300

Please sign in to comment.