Skip to content

Commit

Permalink
Android: Implements getInputAvailable()
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed May 27, 2023
1 parent 6e926bb commit 61f082a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.drpogodin.reactnativeaudio;

import androidx.annotation.NonNull;
import android.content.Context;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.MediaRecorder;
import android.util.Base64;
import androidx.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
Expand All @@ -12,6 +14,7 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -67,6 +70,22 @@ public Map<String,Object> getTypedExportedConstants() {
return constants;
}

@ReactMethod
public void getInputAvailable(Promise promise) {
Context ctxt = getReactApplicationContext().getApplicationContext();
AudioManager manager = (AudioManager)ctxt.getSystemService(
Context.AUDIO_SERVICE);
try {
promise.resolve(manager.getMicrophones().size() > 0);
} catch (IOException e) {
String msg = "Failed to get microphone list";
promise.reject(
"ReactNativeAudio:getInputAvailable",
msg, new Error(msg)
);
}
}

/**
* Sets up and runs an input audio stream.
* @param audioSource Audio source. Valid values are:
Expand Down
2 changes: 2 additions & 0 deletions android/src/oldarch/ReactNativeAudioSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public Map<String,Object> getConstants() {
return this.getTypedExportedConstants();
}

public abstract void getInputAvailable(Promise promise);

public abstract void listen(
double audioSource,
double sampleRate,
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 21
minSdkVersion = 28
compileSdkVersion = 33
targetSdkVersion = 33

Expand Down

0 comments on commit 61f082a

Please sign in to comment.