nosnia-audio-recorder 0.8.4 → 0.8.5

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.
@@ -19,7 +19,7 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
19
19
  private var mediaPlayer: MediaPlayer? = null
20
20
  private var currentFilePath: String? = null
21
21
  private var isPlaying = false
22
-
22
+
23
23
  private val progressHandler = Handler(Looper.getMainLooper())
24
24
  private val progressRunnable = object : Runnable {
25
25
  override fun run() {
@@ -27,38 +27,37 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
27
27
  if (isPlaying && player.isPlaying) {
28
28
  val currentTime = player.currentPosition.toLong()
29
29
  val duration = player.duration.toLong()
30
-
30
+
31
31
  sendEvent("onPlaybackProgress", Arguments.createMap().apply {
32
32
  putDouble("currentTime", currentTime.toDouble())
33
33
  putDouble("duration", duration.toDouble())
34
34
  putBoolean("isPlaying", true)
35
35
  })
36
-
36
+
37
37
  progressHandler.postDelayed(this, 100)
38
38
  }
39
39
  }
40
40
  }
41
41
  }
42
-
42
+
43
43
  private fun sendEvent(eventName: String, params: WritableMap?) {
44
- reactApplicationContext
44
+ reactContext
45
45
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
46
46
  .emit(eventName, params)
47
47
  }
48
-
48
+
49
49
  private fun startProgressUpdates() {
50
50
  progressHandler.post(progressRunnable)
51
51
  }
52
-
52
+
53
53
  private fun stopProgressUpdates() {
54
54
  progressHandler.removeCallbacks(progressRunnable)
55
55
  }
56
56
 
57
- override fun getName(): String {
58
- return NAME
59
- }
57
+ override fun getName(): String = NAME
60
58
 
61
- override fun startPlaying(options: ReadableMap, promise: Promise) {
59
+ @ReactMethod
60
+ fun startPlaying(options: ReadableMap, promise: Promise) {
62
61
  try {
63
62
  val filePath = options.getString("filePath")
64
63
  if (filePath == null) {
@@ -78,33 +77,31 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
78
77
  false
79
78
  }
80
79
 
81
- // Check if file exists
82
80
  val file = File(filePath)
83
81
  if (!file.exists()) {
84
82
  promise.reject("FILE_NOT_FOUND", "Audio file not found: $filePath")
85
83
  return
86
84
  }
87
85
 
88
- // Release existing player if any
89
86
  mediaPlayer?.release()
90
87
 
91
88
  mediaPlayer = MediaPlayer().apply {
92
89
  setDataSource(filePath)
93
90
  setVolume(volume, volume)
94
91
  isLooping = loop
95
-
92
+
96
93
  setOnCompletionListener {
97
94
  isPlaying = false
98
95
  stopProgressUpdates()
99
96
  sendEvent("onPlaybackComplete", Arguments.createMap())
100
97
  }
101
-
102
- setOnErrorListener { _, what, extra ->
98
+
99
+ setOnErrorListener { _, _, _ ->
103
100
  isPlaying = false
104
101
  stopProgressUpdates()
105
102
  true
106
103
  }
107
-
104
+
108
105
  prepare()
109
106
  start()
110
107
  }
@@ -121,10 +118,11 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
121
118
  }
122
119
  }
123
120
 
124
- override fun stopPlaying(promise: Promise) {
121
+ @ReactMethod
122
+ fun stopPlaying(promise: Promise) {
125
123
  try {
126
124
  stopProgressUpdates()
127
-
125
+
128
126
  mediaPlayer?.apply {
129
127
  if (isPlaying) {
130
128
  stop()
@@ -134,14 +132,15 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
134
132
  mediaPlayer = null
135
133
  isPlaying = false
136
134
  currentFilePath = null
137
-
135
+
138
136
  promise.resolve(null)
139
137
  } catch (e: Exception) {
140
138
  promise.reject("STOP_PLAYING_ERROR", e.message, e)
141
139
  }
142
140
  }
143
141
 
144
- override fun pausePlaying(promise: Promise) {
142
+ @ReactMethod
143
+ fun pausePlaying(promise: Promise) {
145
144
  try {
146
145
  if (!isPlaying || mediaPlayer == null) {
147
146
  promise.reject("NOT_PLAYING", "No playback in progress")
@@ -156,7 +155,8 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
156
155
  }
157
156
  }
158
157
 
159
- override fun resumePlaying(promise: Promise) {
158
+ @ReactMethod
159
+ fun resumePlaying(promise: Promise) {
160
160
  try {
161
161
  if (isPlaying || mediaPlayer == null) {
162
162
  promise.reject("NOT_PAUSED", "Playback is not paused")
@@ -171,7 +171,8 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
171
171
  }
172
172
  }
173
173
 
174
- override fun seekToTime(time: Double, promise: Promise) {
174
+ @ReactMethod
175
+ fun seekToTime(time: Double, promise: Promise) {
175
176
  try {
176
177
  if (mediaPlayer == null) {
177
178
  promise.reject("NO_PLAYER", "No audio player initialized")
@@ -186,7 +187,8 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
186
187
  }
187
188
  }
188
189
 
189
- override fun setVolume(volume: Double, promise: Promise) {
190
+ @ReactMethod
191
+ fun setVolume(volume: Double, promise: Promise) {
190
192
  try {
191
193
  if (mediaPlayer == null) {
192
194
  promise.reject("NO_PLAYER", "No audio player initialized")
@@ -201,11 +203,12 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
201
203
  }
202
204
  }
203
205
 
204
- override fun getPlayerStatus(promise: Promise) {
206
+ @ReactMethod
207
+ fun getPlayerStatus(promise: Promise) {
205
208
  try {
206
209
  val status = WritableNativeMap().apply {
207
210
  putBoolean("isPlaying", isPlaying)
208
-
211
+
209
212
  if (mediaPlayer != null) {
210
213
  putDouble("duration", mediaPlayer!!.duration.toDouble())
211
214
  putDouble("currentTime", mediaPlayer!!.currentPosition.toDouble())
@@ -213,7 +216,7 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
213
216
  putDouble("duration", 0.0)
214
217
  putDouble("currentTime", 0.0)
215
218
  }
216
-
219
+
217
220
  if (currentFilePath != null) {
218
221
  putString("currentFilePath", currentFilePath)
219
222
  }
@@ -230,8 +233,4 @@ class NosniaAudioPlayerModule(private val reactContext: ReactApplicationContext)
230
233
  mediaPlayer?.release()
231
234
  mediaPlayer = null
232
235
  }
233
-
234
- companion object {
235
- const val NAME = "NosniaAudioPlayer"
236
- }
237
236
  }
@@ -435,8 +435,4 @@ class NosniaAudioRecorderModule(private val reactContext: ReactApplicationContex
435
435
  val timestamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
436
436
  return "recording_$timestamp.m4a"
437
437
  }
438
-
439
- companion object {
440
- const val NAME = "NosniaAudioRecorder"
441
- }
442
438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
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",