Skip to content

Commit

Permalink
Implementing setSpeed for android (#169)
Browse files Browse the repository at this point in the history
* remove player.prepare

* Implementing setSpeed for android

* Updating feature table with android setSpeed
  • Loading branch information
twitwi authored and benvium committed May 8, 2017
1 parent 2e3fa46 commit 31132db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Get/set volume | ✓ | ✓ | ✓
Get/set pan | ✓ | |
Get/set loops | ✓ | ✓ | ✓
Get/set current time | ✓ | ✓ | ✓
Set speed | ✓ | |
Set speed | ✓ | |

## Installation

Expand Down
19 changes: 8 additions & 11 deletions android/src/main/java/com/zmxv/RNSound/RNSoundModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ public void prepare(final String fileName, final Integer key, final Callback cal
callback.invoke(e);
return;
}
try {
player.prepare();
} catch (Exception exception) {
Log.e("RNSoundModule", "Exception", exception);

WritableMap e = Arguments.createMap();
e.putInt("code", -1);
e.putString("message", exception.getMessage());
callback.invoke(e);
return;
}
this.playerPool.put(key, player);
WritableMap props = Arguments.createMap();
props.putDouble("duration", player.getDuration() * .001);
Expand Down Expand Up @@ -157,6 +146,14 @@ public void setLooping(final Integer key, final Boolean looping) {
}
}

@ReactMethod
public void setSpeed(final Integer key, final Float speed) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.setPlaybackParams(player.getPlaybackParams().setSpeed(speed));
}
}

@ReactMethod
public void setCurrentTime(final Integer key, final Float sec) {
MediaPlayer player = this.playerPool.get(key);
Expand Down
2 changes: 1 addition & 1 deletion sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Sound.prototype.setNumberOfLoops = function(value) {
Sound.prototype.setSpeed = function(value) {
this._setSpeed = value;
if (this._loaded) {
if (!IsAndroid && !IsWindows) {
if (!IsWindows) {
RNSound.setSpeed(this._key, value);
}
}
Expand Down

0 comments on commit 31132db

Please sign in to comment.