Skip to content

Commit

Permalink
Implemented OpenSL-ES audio recording on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 12, 2020
1 parent fe8ce66 commit 4bb95e8
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 217 deletions.
37 changes: 37 additions & 0 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Expand Up @@ -783,6 +783,7 @@ public static native void onNativeTouch(int touchDevId, int pointerFingerId,
public static native void nativeSetenv(String name, String value);
public static native void onNativeOrientationChanged(int orientation);
public static native void nativeAddTouch(int touchId, String name);
public static native void nativePermissionResult(int requestCode, boolean result);

/**
* This method is called by SDL using JNI.
Expand Down Expand Up @@ -1600,6 +1601,42 @@ public static boolean setSystemCursor(int cursorID) {
}
return true;
}

/**
* This method is called by SDL using JNI.
*/
public static void requestPermission(String permission, int requestCode) {
if (mSingleton != null) {
mSingleton.checkPermission(permission, requestCode);
} else {
nativePermissionResult(requestCode, false);
}
}

/**
* This can be overridden
*/
public void checkPermission(String permission, int requestCode) {
if (Build.VERSION.SDK_INT < 23) {
nativePermissionResult(requestCode, true);
return;
}

if (this.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{permission}, requestCode);
} else {
nativePermissionResult(requestCode, true);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
nativePermissionResult(requestCode, true);
} else {
nativePermissionResult(requestCode, false);
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/audio/SDL_audio.c
Expand Up @@ -1076,7 +1076,7 @@ SDL_GetAudioDeviceName(int index, int iscapture)
return NULL;
}

if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
if (iscapture && !current_audio.impl.HasCaptureSupport) {
SDL_SetError("No capture support");
return NULL;
}
Expand Down Expand Up @@ -1230,7 +1230,7 @@ open_audio_device(const char *devname, int iscapture,
return 0;
}

if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
if (iscapture && !current_audio.impl.HasCaptureSupport) {
SDL_SetError("No capture support");
return 0;
}
Expand Down

0 comments on commit 4bb95e8

Please sign in to comment.