@@ -223,6 +223,7 @@ class AudioPlayer(
223223 if (requestAudioFocus()) {
224224 player.playWhenReady = true
225225 player.play()
226+ emitCurrentDuration()
226227 promise.resolve(true )
227228 startListening(promise)}
228229 else {
@@ -235,6 +236,7 @@ class AudioPlayer(
235236
236237 fun stop () {
237238 stopListening()
239+ emitCurrentDuration()
238240 if (playerListener != null ) {
239241 player.removeListener(playerListener!! )
240242 }
@@ -248,6 +250,7 @@ class AudioPlayer(
248250 try {
249251 stopListening()
250252 player.pause()
253+ emitCurrentDuration()
251254 abandonAudioFocus()
252255 promise?.resolve(true )
253256 } catch (e: Exception ) {
@@ -273,17 +276,22 @@ class AudioPlayer(
273276 return validateAndSetPlaybackSpeed(player, speed)
274277 }
275278
279+
280+ fun emitCurrentDuration () {
281+ val currentPosition = player.currentPosition.toString()
282+ val args: WritableMap = Arguments .createMap()
283+ args.putString(Constants .currentDuration, currentPosition)
284+ args.putString(Constants .playerKey, key)
285+ if (isComponentMounted) {
286+ appContext.getJSModule(DeviceEventManagerModule .RCTDeviceEventEmitter ::class .java)?.emit(" onCurrentDuration" , args)
287+ }
288+ }
289+
276290 private fun startListening (promise : Promise ) {
277291 try {
278292 audioPlaybackListener = object : CountDownTimer (player.duration, UpdateFrequency .Low .value) {
279293 override fun onTick (millisUntilFinished : Long ) {
280- val currentPosition = player.currentPosition.toString()
281- val args: WritableMap = Arguments .createMap()
282- args.putString(Constants .currentDuration, currentPosition)
283- args.putString(Constants .playerKey, key)
284- if (isComponentMounted) {
285- appContext.getJSModule(DeviceEventManagerModule .RCTDeviceEventEmitter ::class .java)?.emit(" onCurrentDuration" , args)
286- }
294+ emitCurrentDuration()
287295 }
288296 override fun onFinish () {}
289297 }.start()
0 commit comments