nosnia-audio-recorder 0.9.10 → 0.9.12
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 +51 -31
- package/package.json +1 -1
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
BOOL _isRecording;
|
|
18
18
|
NSTimer *_progressTimer;
|
|
19
19
|
BOOL _hasListeners;
|
|
20
|
-
double _elapsedTimeMs;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
RCT_EXPORT_MODULE(NosniaAudioRecorder)
|
|
@@ -51,48 +50,69 @@ RCT_EXPORT_MODULE(NosniaAudioRecorder)
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
- (void)startProgressTimer {
|
|
53
|
+
// Invalidate existing timer
|
|
54
54
|
if (_progressTimer) {
|
|
55
55
|
[_progressTimer invalidate];
|
|
56
|
+
_progressTimer = nil;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
NSLog(@"[NosniaAudioRecorder] Starting progress timer");
|
|
59
|
-
_elapsedTimeMs = 0.0;
|
|
60
60
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
// Ensure timer is created on main thread and added to main run loop
|
|
62
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
63
|
+
// Send initial duration event
|
|
64
|
+
[self sendEventWithName:@"onRecordingProgress"
|
|
65
|
+
body:@{
|
|
66
|
+
@"duration": @(0.0),
|
|
67
|
+
@"isRecording": @(self->_audioRecorder && self->_audioRecorder.isRecording)
|
|
68
|
+
}];
|
|
69
|
+
|
|
70
|
+
// Create and schedule timer on main run loop
|
|
71
|
+
self->_progressTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
|
|
72
|
+
target:self
|
|
73
|
+
selector:@selector(onProgressTimerTick:)
|
|
74
|
+
userInfo:nil
|
|
75
|
+
repeats:YES];
|
|
76
|
+
|
|
77
|
+
// Ensure timer fires on main run loop
|
|
78
|
+
[[NSRunLoop mainRunLoop] addTimer:self->_progressTimer forMode:NSRunLoopCommonModes];
|
|
79
|
+
|
|
80
|
+
NSLog(@"[NosniaAudioRecorder] Progress timer scheduled on main thread");
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
- (void)onProgressTimerTick:(NSTimer *)timer {
|
|
85
|
+
if (!_audioRecorder || !_isRecording) {
|
|
86
|
+
[self stopProgressTimer];
|
|
87
|
+
return;
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
}];
|
|
90
|
+
// Update meters to ensure accurate currentTime reading
|
|
91
|
+
[_audioRecorder updateMeters];
|
|
92
|
+
|
|
93
|
+
// Use the recorder's currentTime directly
|
|
94
|
+
double durationMs = _audioRecorder.currentTime * 1000.0;
|
|
95
|
+
|
|
96
|
+
NSLog(@"[NosniaAudioRecorder] Duration: %.0f ms (currentTime: %.4f seconds)",
|
|
97
|
+
durationMs, _audioRecorder.currentTime);
|
|
98
|
+
|
|
99
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
100
|
+
[self sendEventWithName:@"onRecordingProgress"
|
|
101
|
+
body:@{
|
|
102
|
+
@"duration": @(durationMs),
|
|
103
|
+
@"isRecording": @(self->_audioRecorder.isRecording)
|
|
104
|
+
}];
|
|
105
|
+
});
|
|
90
106
|
}
|
|
91
107
|
|
|
92
108
|
- (void)stopProgressTimer {
|
|
93
109
|
if (_progressTimer) {
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
111
|
+
if (self->_progressTimer) {
|
|
112
|
+
[self->_progressTimer invalidate];
|
|
113
|
+
self->_progressTimer = nil;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
96
116
|
}
|
|
97
117
|
}
|
|
98
118
|
|
package/package.json
CHANGED