Skip to content

Commit 1c8efab

Browse files
committed
1 parent 6dd4c71 commit 1c8efab

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();
@@ -28,6 +33,8 @@ @implementation RNAudioRecord
2833
RCT_EXPORT_METHOD(start) {
2934
RCTLogInfo(@"start");
3035

36+
[self savePreviousCategory];
37+
3138
// most audio players set session category to "Playback", record won't work in this mode
3239
// therefore set session category to "Record" before recording
3340
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];
@@ -56,6 +63,7 @@ @implementation RNAudioRecord
5663
AudioQueueDispose(_recordState.mQueue, true);
5764
AudioFileClose(_recordState.mAudioFile);
5865
}
66+
[self restorePreviousCategory];
5967
resolve(_filePath);
6068
unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:_filePath error:nil] fileSize];
6169
RCTLogInfo(@"file path %@", _filePath);
@@ -103,4 +111,15 @@ - (void)dealloc {
103111
AudioQueueDispose(_recordState.mQueue, true);
104112
}
105113

114+
- (void)savePreviousCategory {
115+
self.previousCategory = [AVAudioSession sharedInstance].category;
116+
}
117+
118+
- (void)restorePreviousCategory {
119+
if (self.previousCategory) {
120+
[[AVAudioSession sharedInstance] setCategory:self.previousCategory error:nil];
121+
self.previousCategory = nil;
122+
}
123+
}
124+
106125
@end

0 commit comments

Comments
 (0)