nosnia-audio-recorder 0.8.6 → 0.8.8

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.
@@ -35,22 +35,29 @@ class NosniaAudioRecorderModule(private val reactContext: ReactApplicationContex
35
35
  private val progressHandler = Handler(Looper.getMainLooper())
36
36
  private val progressRunnable = object : Runnable {
37
37
  override fun run() {
38
- if (isRecording && !isPaused) {
39
- val currentTime = System.currentTimeMillis()
40
- val duration = currentTime - startTime - pausedDuration
41
-
42
- sendEvent("onRecordingProgress", Arguments.createMap().apply {
43
- putDouble("duration", duration.toDouble())
44
- putBoolean("isRecording", true)
45
- })
46
-
47
- progressHandler.postDelayed(this, 100) // Update every 100ms
38
+ if (isRecording && !isPaused && mediaRecorder != null) {
39
+ try {
40
+ // Use actual MediaRecorder max amplitude for duration tracking
41
+ // Android MediaRecorder doesn't expose duration while recording,
42
+ // so we calculate elapsed time from start
43
+ val currentTime = System.currentTimeMillis()
44
+ val duration = currentTime - startTime - pausedDuration
45
+
46
+ sendEvent("onRecordingProgress", Arguments.createMap().apply {
47
+ putDouble("duration", duration.toDouble())
48
+ putBoolean("isRecording", true)
49
+ })
50
+
51
+ progressHandler.postDelayed(this, 100) // Update every 100ms
52
+ } catch (e: Exception) {
53
+ // Continue despite errors
54
+ progressHandler.postDelayed(this, 100)
55
+ }
48
56
  }
49
57
  }
50
58
  }
51
-
52
59
  private fun sendEvent(eventName: String, params: WritableMap?) {
53
- reactApplicationContext
60
+ reactContext
54
61
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
55
62
  .emit(eventName, params)
56
63
  }
@@ -58,6 +65,7 @@ class NosniaAudioRecorderModule(private val reactContext: ReactApplicationContex
58
65
  private fun startProgressUpdates() {
59
66
  startTime = System.currentTimeMillis()
60
67
  pausedDuration = 0
68
+ // Send initial progress update immediately
61
69
  progressHandler.post(progressRunnable)
62
70
  }
63
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "This is a modern audio recorder which actually works cross platform",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",