|
1 | 1 | #import "RNAudioRecord.h"
|
2 | 2 |
|
| 3 | +@interface RNAudioRecord () |
| 4 | +@property (nonatomic, nullable, copy) AVAudioSessionCategory previousCategory; |
| 5 | +@end |
| 6 | + |
| 7 | + |
3 | 8 | @implementation RNAudioRecord
|
4 | 9 |
|
5 | 10 | RCT_EXPORT_MODULE();
|
@@ -29,6 +34,8 @@ @implementation RNAudioRecord
|
29 | 34 | RCT_EXPORT_METHOD(start) {
|
30 | 35 | RCTLogInfo(@"start");
|
31 | 36 |
|
| 37 | + [self savePreviousCategory]; |
| 38 | + |
32 | 39 | // most audio players set session category to "Playback", record won't work in this mode
|
33 | 40 | // therefore set session category to "Record" before recording
|
34 | 41 | [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];
|
@@ -57,6 +64,7 @@ @implementation RNAudioRecord
|
57 | 64 | AudioQueueDispose(_recordState.mQueue, true);
|
58 | 65 | AudioFileClose(_recordState.mAudioFile);
|
59 | 66 | }
|
| 67 | + [self restorePreviousCategory]; |
60 | 68 | resolve(_filePath);
|
61 | 69 | unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:_filePath error:nil] fileSize];
|
62 | 70 | RCTLogInfo(@"file path %@", _filePath);
|
@@ -118,4 +126,15 @@ + (void)createDir: (NSString *) filePath {
|
118 | 126 | }
|
119 | 127 | }
|
120 | 128 |
|
| 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 | + |
121 | 140 | @end
|
0 commit comments