Skip to content

Commit 03801cf

Browse files
committed
1 parent 9001e45 commit 03801cf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ios/RNAudioRecord.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#import "RNAudioRecord.h"
22

3+
@interface RNAudioRecord ()
4+
@property (nonatomic, nullable, copy) AVAudioSessionCategory previousCategory;
5+
@end
6+
7+
38
@implementation RNAudioRecord
49

510
RCT_EXPORT_MODULE();
@@ -29,6 +34,8 @@ @implementation RNAudioRecord
2934
RCT_EXPORT_METHOD(start) {
3035
RCTLogInfo(@"start");
3136

37+
[self savePreviousCategory];
38+
3239
// most audio players set session category to "Playback", record won't work in this mode
3340
// therefore set session category to "Record" before recording
3441
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];
@@ -57,6 +64,7 @@ @implementation RNAudioRecord
5764
AudioQueueDispose(_recordState.mQueue, true);
5865
AudioFileClose(_recordState.mAudioFile);
5966
}
67+
[self restorePreviousCategory];
6068
resolve(_filePath);
6169
unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:_filePath error:nil] fileSize];
6270
RCTLogInfo(@"file path %@", _filePath);
@@ -118,4 +126,15 @@ + (void)createDir: (NSString *) filePath {
118126
}
119127
}
120128

129+
- (void)savePreviousCategory {
130+
self.previousCategory = [AVAudioSession sharedInstance].category;
131+
}
132+
133+
- (void)restorePreviousCategory {
134+
if (self.previousCategory) {
135+
[[AVAudioSession sharedInstance] setCategory:self.previousCategory error:nil];
136+
self.previousCategory = nil;
137+
}
138+
}
139+
121140
@end

0 commit comments

Comments
 (0)