Skip to content

Commit 31132db

Browse files
twitwibenvium
authored andcommitted
Implementing setSpeed for android (#169)
* remove player.prepare * Implementing setSpeed for android * Updating feature table with android setSpeed
1 parent 2e3fa46 commit 31132db

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Get/set volume | ✓ | ✓ | ✓
2121
Get/set pan | ✓ | |
2222
Get/set loops | ✓ | ✓ | ✓
2323
Get/set current time | ✓ | ✓ | ✓
24-
Set speed | ✓ | |
24+
Set speed | ✓ | |
2525

2626
## Installation
2727

android/src/main/java/com/zmxv/RNSound/RNSoundModule.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ public void prepare(final String fileName, final Integer key, final Callback cal
4444
callback.invoke(e);
4545
return;
4646
}
47-
try {
48-
player.prepare();
49-
} catch (Exception exception) {
50-
Log.e("RNSoundModule", "Exception", exception);
51-
52-
WritableMap e = Arguments.createMap();
53-
e.putInt("code", -1);
54-
e.putString("message", exception.getMessage());
55-
callback.invoke(e);
56-
return;
57-
}
5847
this.playerPool.put(key, player);
5948
WritableMap props = Arguments.createMap();
6049
props.putDouble("duration", player.getDuration() * .001);
@@ -157,6 +146,14 @@ public void setLooping(final Integer key, final Boolean looping) {
157146
}
158147
}
159148

149+
@ReactMethod
150+
public void setSpeed(final Integer key, final Float speed) {
151+
MediaPlayer player = this.playerPool.get(key);
152+
if (player != null) {
153+
player.setPlaybackParams(player.getPlaybackParams().setSpeed(speed));
154+
}
155+
}
156+
160157
@ReactMethod
161158
public void setCurrentTime(final Integer key, final Float sec) {
162159
MediaPlayer player = this.playerPool.get(key);

sound.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Sound.prototype.setNumberOfLoops = function(value) {
135135
Sound.prototype.setSpeed = function(value) {
136136
this._setSpeed = value;
137137
if (this._loaded) {
138-
if (!IsAndroid && !IsWindows) {
138+
if (!IsWindows) {
139139
RNSound.setSpeed(this._key, value);
140140
}
141141
}

0 commit comments

Comments
 (0)