Skip to content

Commit

Permalink
Fix: normalize seekTo time argument (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonBorovoi authored Aug 12, 2021
1 parent 64a2051 commit 9517414
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,13 @@ class RNAudioRecorderPlayerModule(private val reactContext: ReactApplicationCont
}

@ReactMethod
fun seekToPlayer(time: Int, promise: Promise) {
fun seekToPlayer(time: Double, promise: Promise) {
if (mediaPlayer == null) {
promise.reject("seekTo", "mediaPlayer is null on seek.")
return
}

val millis = time * 1000
mediaPlayer!!.seekTo(millis)
mediaPlayer!!.seekTo(time.toInt())
promise.resolve("pause player")
}

Expand Down
4 changes: 1 addition & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,10 @@ class AudioRecorderPlayer {

/**
* Seek to.
* @param {number} time position seek to in second.
* @param {number} time position seek to in millisecond.
* @returns {Promise<string>}
*/
seekToPlayer = async (time: number): Promise<string> => {
if (Platform.OS === 'ios') time = time / 1000;

return RNAudioRecorderPlayer.seekToPlayer(time);
};

Expand Down
2 changes: 1 addition & 1 deletion ios/RNAudioRecorderPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class RNAudioRecorderPlayer: RCTEventEmitter, AVAudioRecorderDelegate {
return reject("RNAudioPlayerRecorder", "Player is null", nil)
}

audioPlayer.seek(to: CMTime(seconds: time, preferredTimescale: CMTimeScale(NSEC_PER_SEC)))
audioPlayer.seek(to: CMTime(seconds: time / 1000, preferredTimescale: CMTimeScale(NSEC_PER_SEC)))
resolve("Resumed!")
}

Expand Down

0 comments on commit 9517414

Please sign in to comment.