Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Implements onSeekCompleteListener #216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions android/src/main/java/com/zmxv/RNSound/RNSoundModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnSeekCompleteListener;
import android.net.Uri;
import android.media.AudioManager;

Expand Down Expand Up @@ -217,9 +218,15 @@ public void setSpeed(final Integer key, final Float speed) {
}

@ReactMethod
public void setCurrentTime(final Integer key, final Float sec) {
MediaPlayer player = this.playerPool.get(key);
public void setCurrentTime(final Integer key, final Float sec, final Callback callback) {
final MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.setOnSeekCompleteListener(new OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer mp) {
callback.invoke(player.getCurrentPosition() * .001);
}
});
player.seekTo((int)Math.round(sec * 1000));
}
}
Expand Down
4 changes: 2 additions & 2 deletions sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ Sound.prototype.getCurrentTime = function(callback) {
}
};

Sound.prototype.setCurrentTime = function(value) {
Sound.prototype.setCurrentTime = function(value, callback) {
if (this._loaded) {
RNSound.setCurrentTime(this._key, value);
RNSound.setCurrentTime(this._key, value, callback);
}
return this;
};
Expand Down