nosnia-audio-recorder 0.7.7 → 0.8.1

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.
@@ -103,7 +103,7 @@ RCT_EXPORT_MODULE(NosniaAudioRecorder)
103
103
  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
104
104
  [formatter setDateFormat:@"yyyyMMdd_HHmmss"];
105
105
  NSString *timestamp = [formatter stringFromDate:[NSDate date]];
106
- return [NSString stringWithFormat:@"recording_%@.wav", timestamp];
106
+ return [NSString stringWithFormat:@"recording_%@.m4a", timestamp];
107
107
  }
108
108
 
109
109
  RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
@@ -233,17 +233,16 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
233
233
 
234
234
  // Create recording settings dictionary with safety checks
235
235
  @try {
236
- // Use Linear PCM as the most basic and universally supported format
237
- // iOS will handle audio encoding reliably with PCM
238
- NSDictionary *recordingSettings = @{
239
- AVFormatIDKey: @(kAudioFormatLinearPCM),
240
- AVSampleRateKey: sampleRate,
241
- AVNumberOfChannelsKey: channels,
242
- AVLinearPCMBitDepthKey: @(16),
243
- AVLinearPCMIsBigEndianKey: @(NO),
244
- AVLinearPCMIsNonInterleaved: @(NO),
245
- AVEncoderAudioQualityKey: @(AVAudioQualityHigh)
246
- };
236
+ // Use MPEG4AAC format for MP3-compatible output
237
+ // Only use essential keys that are universally supported
238
+ NSMutableDictionary *recordingSettings = [NSMutableDictionary dictionary];
239
+ [recordingSettings setObject:@(kAudioFormatMPEG4AAC) forKey:AVFormatIDKey];
240
+ [recordingSettings setObject:sampleRate forKey:AVSampleRateKey];
241
+ [recordingSettings setObject:channels forKey:AVNumberOfChannelsKey];
242
+ [recordingSettings setObject:bitrate forKey:AVEncoderBitRateKey];
243
+ [recordingSettings setObject:@(AVAudioQualityMedium) forKey:AVEncoderAudioQualityKey];
244
+
245
+ NSLog(@"[NosniaAudioRecorder] Recording settings: %@", recordingSettings);
247
246
 
248
247
  // Validate settings dictionary created successfully
249
248
  if (!recordingSettings || recordingSettings.count == 0) {
@@ -253,7 +252,7 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
253
252
 
254
253
  // Validate all required keys are present
255
254
  if (!recordingSettings[AVFormatIDKey] || !recordingSettings[AVSampleRateKey] ||
256
- !recordingSettings[AVNumberOfChannelsKey] || !recordingSettings[AVLinearPCMBitDepthKey]) {
255
+ !recordingSettings[AVNumberOfChannelsKey] || !recordingSettings[AVEncoderBitRateKey]) {
257
256
  reject(@"SETTINGS_ERROR", @"Incomplete recording settings", nil);
258
257
  return;
259
258
  }
@@ -287,11 +286,36 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
287
286
 
288
287
  // Try to prepare recorder first
289
288
  NSLog(@"[NosniaAudioRecorder] Preparing to record with settings: %@", _audioRecorder.settings);
289
+ NSLog(@"[NosniaAudioRecorder] Recording URL: %@", _recordingURL);
290
+
290
291
  if (![_audioRecorder prepareToRecord]) {
291
- NSLog(@"[NosniaAudioRecorder] Failed to prepare audio recorder");
292
- reject(@"PREPARE_ERROR", @"Failed to prepare audio recorder for recording", nil);
293
- _audioRecorder = nil;
294
- return;
292
+ NSLog(@"[NosniaAudioRecorder] Failed to prepare audio recorder. Recorder: %@, Error: %@", _audioRecorder, _audioRecorder.deviceCurrentTime);
293
+ NSLog(@"[NosniaAudioRecorder] Recording settings that failed: Format=%@, SampleRate=%@, Channels=%@, Bitrate=%@",
294
+ _audioRecorder.settings[AVFormatIDKey],
295
+ _audioRecorder.settings[AVSampleRateKey],
296
+ _audioRecorder.settings[AVNumberOfChannelsKey],
297
+ _audioRecorder.settings[AVEncoderBitRateKey]);
298
+
299
+ // Try with fallback minimal settings
300
+ NSLog(@"[NosniaAudioRecorder] Attempting fallback with minimal settings");
301
+ NSDictionary *fallbackSettings = @{
302
+ AVFormatIDKey: @(kAudioFormatMPEG4AAC),
303
+ AVSampleRateKey: @(44100.0),
304
+ AVNumberOfChannelsKey: @(1),
305
+ AVEncoderBitRateKey: @(128000),
306
+ AVEncoderAudioQualityKey: @(AVAudioQualityMedium)
307
+ };
308
+
309
+ NSError *fallbackError = nil;
310
+ _audioRecorder = [[AVAudioRecorder alloc] initWithURL:_recordingURL
311
+ settings:fallbackSettings
312
+ error:&fallbackError];
313
+ if (fallbackError || ![_audioRecorder prepareToRecord]) {
314
+ NSLog(@"[NosniaAudioRecorder] Fallback also failed: %@", fallbackError);
315
+ reject(@"PREPARE_ERROR", @"Failed to prepare audio recorder for recording with both standard and fallback settings", nil);
316
+ _audioRecorder = nil;
317
+ return;
318
+ }
295
319
  }
296
320
  NSLog(@"[NosniaAudioRecorder] Recorder prepared successfully");
297
321
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.7.7",
3
+ "version": "0.8.1",
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",