Skip to content

Commit

Permalink
fix(ios): currentPosition and duration may never equal during playing (
Browse files Browse the repository at this point in the history
  • Loading branch information
Phecda authored Nov 9, 2023
1 parent dde8155 commit 745d5e2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ios/RNAudioRecorderPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,22 @@ class RNAudioRecorderPlayer: RCTEventEmitter, AVAudioRecorderDelegate {
}

addPeriodicTimeObserver()
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: Notification.Name.AVPlayerItemDidPlayToEndTime, object: audioPlayer.currentItem)
audioPlayer.play()
resolve(audioFileURL?.absoluteString)
}

@objc
public func playerDidFinishPlaying(notification: Notification) {
if let playerItem = notification.object as? AVPlayerItem {
let duration = playerItem.duration.seconds * 1000
self.sendEvent(withName: "rn-playback", body: [
"isMuted": self.audioPlayer?.isMuted as Any,
"currentPosition": duration,
"duration": duration,
])
}
}

@objc(stopPlayer:rejecter:)
public func stopPlayer(
Expand Down

0 comments on commit 745d5e2

Please sign in to comment.