nosnia-audio-recorder 0.6.3 → 0.7.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.
- package/ios/NosniaAudioRecorder.mm +27 -13
- package/package.json +1 -1
|
@@ -161,9 +161,9 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
|
|
|
161
161
|
if (!sampleRate || ![sampleRate isKindOfClass:[NSNumber class]] || [sampleRate integerValue] <= 0) {
|
|
162
162
|
sampleRate = @(44100);
|
|
163
163
|
} else {
|
|
164
|
-
// AAC
|
|
164
|
+
// AAC/MP3 compatible sample rates: 8000, 16000, 22050, 32000, 44100, 48000
|
|
165
165
|
NSInteger rate = [sampleRate integerValue];
|
|
166
|
-
NSArray *validRates = @[@8000, @16000, @22050, @
|
|
166
|
+
NSArray *validRates = @[@8000, @16000, @22050, @32000, @44100, @48000];
|
|
167
167
|
if (![validRates containsObject:sampleRate]) {
|
|
168
168
|
sampleRate = @(44100); // Default to 44100 if invalid
|
|
169
169
|
}
|
|
@@ -176,17 +176,30 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
|
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
// Set audio category - use Record category with
|
|
179
|
+
// Set audio category - use Record category with multiple options for compatibility
|
|
180
180
|
NSError *categoryError = nil;
|
|
181
|
+
AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionDuckOthers |
|
|
182
|
+
AVAudioSessionCategoryOptionDefaultToSpeaker;
|
|
181
183
|
BOOL categorySuccess = [audioSession setCategory:AVAudioSessionCategoryRecord
|
|
182
|
-
withOptions:
|
|
184
|
+
withOptions:options
|
|
183
185
|
error:&categoryError];
|
|
184
186
|
if (!categorySuccess || categoryError) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
// Try without DefaultToSpeaker if it fails
|
|
188
|
+
categoryError = nil;
|
|
189
|
+
categorySuccess = [audioSession setCategory:AVAudioSessionCategoryRecord
|
|
190
|
+
withOptions:AVAudioSessionCategoryOptionDuckOthers
|
|
191
|
+
error:&categoryError];
|
|
192
|
+
if (!categorySuccess || categoryError) {
|
|
193
|
+
NSString *msg = categoryError ? categoryError.description : @"Failed to set audio category";
|
|
194
|
+
reject(@"AUDIO_SESSION_ERROR", msg, categoryError);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
188
197
|
}
|
|
189
198
|
|
|
199
|
+
// Set audio mode to measurement for recording
|
|
200
|
+
NSError *modeError = nil;
|
|
201
|
+
[audioSession setMode:AVAudioSessionModeMeasurement error:&modeError];
|
|
202
|
+
|
|
190
203
|
// Activate audio session
|
|
191
204
|
NSError *activateError = nil;
|
|
192
205
|
BOOL activateSuccess = [audioSession setActive:YES error:&activateError];
|
|
@@ -204,13 +217,14 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
|
|
|
204
217
|
|
|
205
218
|
// Create recording settings dictionary with safety checks
|
|
206
219
|
@try {
|
|
207
|
-
// Use
|
|
220
|
+
// Use AAC format with validated parameters
|
|
221
|
+
// AVAudioRecorder will encode to M4A/AAC automatically
|
|
208
222
|
NSDictionary *recordingSettings = @{
|
|
209
|
-
AVFormatIDKey: @(
|
|
210
|
-
AVSampleRateKey:
|
|
211
|
-
AVNumberOfChannelsKey:
|
|
212
|
-
AVEncoderBitRateKey:
|
|
213
|
-
AVEncoderAudioQualityKey: @(
|
|
223
|
+
AVFormatIDKey: @(kAudioFormatMPEG4AAC),
|
|
224
|
+
AVSampleRateKey: sampleRate,
|
|
225
|
+
AVNumberOfChannelsKey: channels,
|
|
226
|
+
AVEncoderBitRateKey: bitrate,
|
|
227
|
+
AVEncoderAudioQualityKey: @(AVAudioQualityHigh)
|
|
214
228
|
};
|
|
215
229
|
|
|
216
230
|
// Validate settings dictionary created successfully
|
package/package.json
CHANGED