Im trying to add an new function to an existing react native library called react-native-system-setting, for my application i need to be able to simulate key events for playing, pausing and skipping songs on different media players as described here so i added the function "MediaControl" to the react-native-system-setting library:
public SystemSetting(ReactApplicationContext reactContext) {
super(reactContext);
mContext = reactContext;
reactContext.addLifecycleEventListener(this);
am = (AudioManager) mContext.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
wm = (WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
lm = (LocationManager) mContext.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
listenVolume(reactContext);
}
@ReactMethod
public void MediaControl(String Command ) {
long eventtime = SystemClock.uptimeMillis();
switch (Command) {
case "next":
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
am.dispatchMediaKeyEvent(downEvent);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
am.dispatchMediaKeyEvent(upEvent);
case "previous":
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
am.dispatchMediaKeyEvent(downEvent);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
am.dispatchMediaKeyEvent(upEvent);
case "play":
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
am.dispatchMediaKeyEvent(downEvent);
case "pause":
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
am.dispatchMediaKeyEvent(upEvent);
}
}
it builds ok on android studio, but when i try to use the function i get an error:
undefined is not a function (evaluating '_reactNativeSystemSetting2.default.MediaControl("play")')
am i missing something?