Skip to content

Commit 14c362e

Browse files
author
Raj Patel
committed
looping support in android.
1 parent 7dd07f9 commit 14c362e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

android/src/main/java/com/johnsonsu/rnsoundplayer/RNSoundPlayerModule.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ public void setVolume(float volume) throws IOException {
133133
}
134134
}
135135

136+
@ReactMethod
137+
public void setNumberOfLoops(int noOfLooping){
138+
// The expected boolean value
139+
Boolean boolValue;
140+
if (noOfLooping == 0) {
141+
boolValue = false;
142+
}
143+
else {
144+
boolValue = true;
145+
}
146+
147+
if (this.mediaPlayer != null) {
148+
this.mediaPlayer.setLooping(looping);
149+
}
150+
}
151+
136152
@ReactMethod
137153
public void getInfo(
138154
Promise promise) {

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ declare module "react-native-sound-player" {
4848
setSpeaker: (on: boolean) => void;
4949
/** Only available on iOS. If you set this option, your audio will be mixed with audio playing in background apps, such as the Music app. */
5050
setMixAudio: (on: boolean) => void;
51-
/** IOS only. Set the number of loops. A negative value will loop indefinitely until the stop() command is called. */
51+
/** iOS: 0 means to play the sound once, a positive number specifies the number of times to return to the start and play again, a negative number indicates an indefinite loop. Android: 0 means to play the sound once, other numbers indicate an indefinite loop. */
5252
setNumberOfLoops: (loops: number) => void;
5353
/** Get the currentTime and duration of the currently mounted audio media. This function returns a promise which resolves to an Object containing currentTime and duration properties. */
5454
getInfo: () => Promise<{ currentTime: number; duration: number }>;

0 commit comments

Comments
 (0)