8000 Implementation returns a list of audio sources,imp fun setPreferredIn… · micromingle/flutter-webrtc@ef81095 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef81095

Browse files
authored
Implementation returns a list of audio sources,imp fun setPreferredInputDevice (flutter-webrtc#933)
* Implementation returns a list of audio sources,imp fun setPreferredInputDevice * format code
1 parent 0e2278c commit ef81095

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

android/src/main/java/com/cloudwebrtc/webrtc/GetUserMediaImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.hardware.camera2.CameraDevice;
1717
import android.hardware.camera2.CameraManager;
1818
import android.hardware.camera2.CaptureRequest;
19+
import android.media.AudioDeviceInfo;
1920
import android.media.projection.MediaProjection;
2021
import android.media.projection.MediaProjectionManager;
2122
import android.os.Build;
@@ -1062,4 +1063,13 @@ public class VideoCapturerInfo {
10621063
int fps;
10631064
boolean isScreenCapture = false;
10641065
}
1066+
1067+
@RequiresApi(api = VERSION_CODES.M)
1068+
void setPreferredInputDevice(int i){
1069+
android.media.AudioManager audioManager = ((android.media.AudioManager) applicationContext.getSystemService(Context.AUDIO_SERVICE));
1070+
final AudioDeviceInfo[] devices = audioManager.getDevices(android.media.AudioManager.GET_DEVICES_INPUTS);
1071+
if (devices.length>i){
1072+
audioDeviceModule.setPreferredInputDevice(devices[i]);
1073+
}
1074+
}
10651075
}

android/src/main/java/com/cloudwebrtc/webrtc/MethodCallHandlerImpl.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.SurfaceTexture;
1010
import android.hardware.Camera;
1111
import android.hardware.Camera.CameraInfo;
12+
import android.media.AudioDeviceInfo;
1213
import android.os.Build;
1314
import android.util.Log;
1415
import android.util.LongSparseArray;
@@ -673,6 +674,16 @@ public void onMethodCall(MethodCall call, @NonNull Result notSafeResult) {
673674
getTransceivers(peerConnectionId, result);
674675
break;
675676
}
677+
case "setPreferredInputDevice": {
678+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
679+
String deviceId = call.argument("deviceId");
680+
getUserMediaImpl.setPreferredInputDevice(Integer.parseInt(deviceId));
681+
result.success(null);
682+
} else {
683+
result.notImplemented();
684+
}
685+
break;
686+
}
676687
default:
677688
result.notImplemented();
678689
break;
@@ -1124,12 +1135,30 @@ public void getSources(Result result) {
11241135
}
11251136
}
11261137

1127-
ConstraintsMap audio = new ConstraintsMap();
1128-
audio.putString("label", "Audio");
1129-
audio.putString("deviceId", "audio-1");
1130-
audio.putString("facing", "");
1131-
audio.putString("kind", "audioinput");
1132-
array.pushMap(audio);
1138+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
1139+
ConstraintsMap audio = new ConstraintsMap();
1140+
audio.putString("label", "Audio");
1141+
audio.putString("deviceId", "audio-1");
1142+
audio.putString("facing", "");
1143+
audio.putString("kind", "audioinput");
1144+
array.pushMap(audio);
1145+
} else {
1146+
android.media.AudioManager audioManager = ((android.media.AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
1147+
final AudioDeviceInfo[] devices = audioManager.getDevices(android.media.AudioManager.GET_DEVICES_INPUTS);
1148+
for (int i=0;i<devices.length;i++) {
1149+
AudioDeviceInfo device=devices[i];
1150+
int type = (device.getType() & 0xFF);
1151+
String label=Build.VERSION.SDK_INT < Build.VERSION_CODES.P ? String.valueOf(i) : device.getAddress();
1152+
ConstraintsMap audio = new ConstraintsMap();
1153+
audio.putString("label", label);
1154+
audio.putString("deviceId", String.valueOf(i));
1155+
audio.putString("groupId", ""+type);
1156+
audio.putString("facing", "");
1157+
audio.putString("kind", "audioinput");
1158+
array.pushMap(audio);
1159+
}
1160+
}
1161+
11331162

11341163
ConstraintsMap map = new ConstraintsMap();
11351164
map.putArray("sources", array.toArrayList());

0 commit comments

Comments
 (0)
0