nosnia-audio-recorder 0.8.0 → 0.8.2

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 Record category with DuckOthers only
193
+ // Note: DefaultToSpeaker is NOT compatible with Record category
193
194
  NSError *categoryError = nil;
194
- AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionDuckOthers |
195
- AVAudioSessionCategoryOptionDefaultToSpeaker;
195
+ AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionDuckOthers;
196
196
  BOOL categorySuccess = [audioSession setCategory:AVAudioSessionCategoryRecord
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 Record with DuckOthers");
211
206
 
212
207
  // Set audio mode to default for recording
213
208
  NSError *modeError = nil;
@@ -234,14 +229,14 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
234
229
  // Create recording settings dictionary with safety checks
235
230
  @try {
236
231
  // Use MPEG4AAC format for MP3-compatible output
237
- // Creates .m4a files which are MP3-compatible and highly reliable
238
- NSDictionary *recordingSettings = @{
239
- AVFormatIDKey: @(kAudioFormatMPEG4AAC),
240
- AVSampleRateKey: sampleRate,
241
- AVNumberOfChannelsKey: channels,
242
- AVEncoderBitRateKey: bitrate,
243
- AVEncoderAudioQualityKey: @(AVAudioQualityHigh)
244
- };
232
+ // Only use essential keys that are universally supported
233
+ NSMutableDictionary *recordingSettings = [NSMutableDictionary dictionary];
234
+ [recordingSettings setObject:@(kAudioFormatMPEG4AAC) forKey:AVFormatIDKey];
235
+ [recordingSettings setObject:@([sampleRate doubleValue]) forKey:AVSampleRateKey];
236
+ [recordingSettings setObject:channels forKey:AVNumberOfChannelsKey];
237
+ [recordingSettings setObject:bitrate forKey:AVEncoderBitRateKey];
238
+
239
+ NSLog(@"[NosniaAudioRecorder] Recording settings: %@", recordingSettings);
245
240
 
246
241
  // Validate settings dictionary created successfully
247
242
  if (!recordingSettings || recordingSettings.count == 0) {
@@ -285,11 +280,36 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
285
280
 
286
281
  // Try to prepare recorder first
287
282
  NSLog(@"[NosniaAudioRecorder] Preparing to record with settings: %@", _audioRecorder.settings);
283
+ NSLog(@"[NosniaAudioRecorder] Recording URL: %@", _recordingURL);
284
+
288
285
  if (![_audioRecorder prepareToRecord]) {
289
- NSLog(@"[NosniaAudioRecorder] Failed to prepare audio recorder");
290
- reject(@"PREPARE_ERROR", @"Failed to prepare audio recorder for recording", nil);
291
- _audioRecorder = nil;
292
- return;
286
+ NSLog(@"[NosniaAudioRecorder] Failed to prepare audio recorder. Recorder: %@, Error: %@", _audioRecorder, _audioRecorder.deviceCurrentTime);
287
+ NSLog(@"[NosniaAudioRecorder] Recording settings that failed: Format=%@, SampleRate=%@, Channels=%@, Bitrate=%@",
288
+ _audioRecorder.settings[AVFormatIDKey],
289
+ _audioRecorder.settings[AVSampleRateKey],
290
+ _audioRecorder.settings[AVNumberOfChannelsKey],
291
+ _audioRecorder.settings[AVEncoderBitRateKey]);
292
+
293
+ // Try with fallback minimal settings
294
+ NSLog(@"[NosniaAudioRecorder] Attempting fallback with minimal settings");
295
+ NSDictionary *fallbackSettings = @{
296
+ AVFormatIDKey: @(kAudioFormatMPEG4AAC),
297
+ AVSampleRateKey: @(44100.0),
298
+ AVNumberOfChannelsKey: @(1),
299
+ AVEncoderBitRateKey: @(128000),
300
+ AVEncoderAudioQualityKey: @(AVAudioQualityMedium)
301
+ };
302
+
303
+ NSError *fallbackError = nil;
304
+ _audioRecorder = [[AVAudioRecorder alloc] initWithURL:_recordingURL
305
+ settings:fallbackSettings
306
+ error:&fallbackError];
307
+ if (fallbackError || ![_audioRecorder prepareToRecord]) {
308
+ NSLog(@"[NosniaAudioRecorder] Fallback also failed: %@", fallbackError);
309
+ reject(@"PREPARE_ERROR", @"Failed to prepare audio recorder for recording with both standard and fallback settings", nil);
310
+ _audioRecorder = nil;
311
+ return;
312
+ }
293
313
  }
294
314
  NSLog(@"[NosniaAudioRecorder] Recorder prepared successfully");
295
315
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
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",