nosnia-audio-recorder 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -189,25 +189,20 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
189
189
  return;
190
190
  }
191
191
 
192
- // Set audio category - use Record category with multiple options for compatibility
192
+ // Set audio category - use PlayAndRecord for better simulator/device compatibility
193
+ // This works reliably on both real devices and simulators
193
194
  NSError *categoryError = nil;
194
- AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionDuckOthers |
195
- AVAudioSessionCategoryOptionDefaultToSpeaker;
196
- BOOL categorySuccess = [audioSession setCategory:AVAudioSessionCategoryRecord
195
+ AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionDefaultToSpeaker;
196
+ BOOL categorySuccess = [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
197
197
  withOptions:options
198
198
  error:&categoryError];
199
199
  if (!categorySuccess || categoryError) {
200
- // Try without DefaultToSpeaker if it fails
201
- categoryError = nil;
202
- categorySuccess = [audioSession setCategory:AVAudioSessionCategoryRecord
203
- withOptions:AVAudioSessionCategoryOptionDuckOthers
204
- error:&categoryError];
205
- if (!categorySuccess || categoryError) {
206
- NSString *msg = categoryError ? categoryError.description : @"Failed to set audio category";
207
- reject(@"AUDIO_SESSION_ERROR", msg, categoryError);
208
- return;
209
- }
200
+ NSString *msg = categoryError ? categoryError.description : @"Failed to set audio category";
201
+ NSLog(@"[NosniaAudioRecorder] Audio category error: %@", msg);
202
+ reject(@"AUDIO_SESSION_ERROR", msg, categoryError);
203
+ return;
210
204
  }
205
+ NSLog(@"[NosniaAudioRecorder] Audio category set to PlayAndRecord with DefaultToSpeaker");
211
206
 
212
207
  // Set audio mode to default for recording
213
208
  NSError *modeError = nil;
@@ -237,10 +232,9 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
237
232
  // Only use essential keys that are universally supported
238
233
  NSMutableDictionary *recordingSettings = [NSMutableDictionary dictionary];
239
234
  [recordingSettings setObject:@(kAudioFormatMPEG4AAC) forKey:AVFormatIDKey];
240
- [recordingSettings setObject:sampleRate forKey:AVSampleRateKey];
235
+ [recordingSettings setObject:@([sampleRate doubleValue]) forKey:AVSampleRateKey];
241
236
  [recordingSettings setObject:channels forKey:AVNumberOfChannelsKey];
242
237
  [recordingSettings setObject:bitrate forKey:AVEncoderBitRateKey];
243
- [recordingSettings setObject:@(AVAudioQualityMedium) forKey:AVEncoderAudioQualityKey];
244
238
 
245
239
  NSLog(@"[NosniaAudioRecorder] Recording settings: %@", recordingSettings);
246
240
 
@@ -323,14 +317,27 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
323
317
  recordStarted = [_audioRecorder record];
324
318
  if (!recordStarted) {
325
319
  NSLog(@"[NosniaAudioRecorder] Failed to start recording. Recorder is recording: %d", _audioRecorder.recording);
326
- NSString *errorMsg = [NSString stringWithFormat:
327
- @"Failed to start recording. Recorder state: %ld, URL: %@, Settings: %@",
328
- (long)_audioRecorder.recording,
329
- _recordingURL,
330
- _audioRecorder.settings];
331
- reject(@"START_RECORDING_ERROR", errorMsg, recordStartError);
332
- _audioRecorder = nil;
333
- return;
320
+
321
+ // Try alternative: reset audio session and retry
322
+ NSLog(@"[NosniaAudioRecorder] Attempting recovery: resetting audio session");
323
+ NSError *resetError = nil;
324
+ [[AVAudioSession sharedInstance] setActive:NO error:&resetError];
325
+
326
+ NSError *reactivateError = nil;
327
+ [[AVAudioSession sharedInstance] setActive:YES error:&reactivateError];
328
+
329
+ // Retry recording once
330
+ recordStarted = [_audioRecorder record];
331
+ if (!recordStarted) {
332
+ NSString *errorMsg = [NSString stringWithFormat:
333
+ @"Failed to start recording after retry. Recorder state: %ld. This may be a simulator audio limitation. Try on a real device.",
334
+ (long)_audioRecorder.recording];
335
+ NSLog(@"[NosniaAudioRecorder] %@", errorMsg);
336
+ reject(@"START_RECORDING_ERROR", errorMsg, nil);
337
+ _audioRecorder = nil;
338
+ return;
339
+ }
340
+ NSLog(@"[NosniaAudioRecorder] Recovery successful - recording started");
334
341
  }
335
342
  NSLog(@"[NosniaAudioRecorder] Recording started successfully");
336
343
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "This is a modern audio recorder which actually works cross platform",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",