From 49b4ab78fe118dc83218b3152e13aee4247f1bf1 Mon Sep 17 00:00:00 2001 From: Esmaeil Date: Wed, 5 Dec 2018 12:38:06 +0330 Subject: [PATCH 1/2] Update AudioRecorderManger.m Add getCurrentTime method. This method returns a promise when audio is in recording. `onProgress` method return this value each 250 milliseconds. Sometimes you need to get it in a moment. This method can help you. --- ios/AudioRecorderManager.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ios/AudioRecorderManager.m b/ios/AudioRecorderManager.m index 5fdeb1c1..74e8d232 100644 --- a/ios/AudioRecorderManager.m +++ b/ios/AudioRecorderManager.m @@ -294,6 +294,17 @@ - (NSString *) applicationDocumentsDirectory }]; } +RCT_EXPORT_METHOD(getCurrentTime:(RCTPromiseResolveBlock)resolve + rejecter:(__unused RCTPromiseRejectBlock)reject) +{ + if (_audioRecorder && _audioRecorder.isRecording) { + resolve(@(_audioRecorder.currentTime)); + } else { + resolve(@"NO"); + } +} + + - (NSString *)getPathForDirectory:(int)directory { NSArray *paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES); From f36839f22aab37f0396496b822ed839c38f82cf1 Mon Sep 17 00:00:00 2001 From: Esmaeil Date: Wed, 5 Dec 2018 12:41:30 +0330 Subject: [PATCH 2/2] Update index.js To connect JS to native side to run getCurrentTime method. This function return an promise. --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 44f1bff8..8ea28203 100644 --- a/index.js +++ b/index.js @@ -74,6 +74,11 @@ var AudioRecorder = { stopRecording: function() { return AudioRecorderManager.stopRecording(); }, + getCurrentTime: function() { + if (Platform.OS === 'ios') { + return AudioRecorderManager.getCurrentTime(); + } + }, checkAuthorizationStatus: AudioRecorderManager.checkAuthorizationStatus, requestAuthorization: () => { if (Platform.OS === 'ios')