Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,42 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.Callback;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;

public class RNAudioPlayerModule extends ReactContextBaseJavaModule {
ReactApplicationContext reactContext;
MediaPlayer mp;
ReactApplicationContext reactContext;
MediaPlayer mp;

public RNAudioPlayerModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
public RNAudioPlayerModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public String getName() {
return "RNAudioPlayer";
}
@Override
public String getName() {
return "RNAudioPlayer";
}

@ReactMethod
public void play(String audio) {
String fname = audio.toLowerCase();
int resID = this.reactContext.getResources().getIdentifier(fname, "raw", this.reactContext.getPackageName());
mp = MediaPlayer.create(this.reactContext, resID);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.reset();
mp.release();
mp = null;
}
});
}
@ReactMethod
public void play(String audio) {
String fname = audio.toLowerCase();
int resID = this.reactContext.getResources().getIdentifier(fname, "raw", this.reactContext.getPackageName());
mp = MediaPlayer.create(this.reactContext, resID);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.reset();
mp.release();
mp = null;
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("audioEnd", null);
}
});
}
}