mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-19 19:15:08 +00:00
Refactor audio sources
Store the target audio source integer (one of the constants from android.media.MediaRecorder.AudioSource) in the AudioSource enum (or -1 if not relevant). This will simplify adding new audio sources. PR #5870 <https://github.com/Genymobile/scrcpy/pull/5870>
This commit is contained in:
parent
3a0703f428
commit
609719bde0
2 changed files with 13 additions and 17 deletions
|
@ -12,7 +12,6 @@ import android.content.ComponentName;
|
|||
import android.content.Intent;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaRecorder;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
|
||||
|
@ -32,18 +31,7 @@ public class AudioDirectCapture implements AudioCapture {
|
|||
private AudioRecordReader reader;
|
||||
|
||||
public AudioDirectCapture(AudioSource audioSource) {
|
||||
this.audioSource = getAudioSourceValue(audioSource);
|
||||
}
|
||||
|
||||
private static int getAudioSourceValue(AudioSource audioSource) {
|
||||
switch (audioSource) {
|
||||
case OUTPUT:
|
||||
return MediaRecorder.AudioSource.REMOTE_SUBMIX;
|
||||
case MIC:
|
||||
return MediaRecorder.AudioSource.MIC;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported audio source: " + audioSource);
|
||||
}
|
||||
this.audioSource = audioSource.getDirectAudioSource();
|
||||
}
|
||||
|
||||
@TargetApi(AndroidVersions.API_23_ANDROID_6_0)
|
||||
|
|
|
@ -1,20 +1,28 @@
|
|||
package com.genymobile.scrcpy.audio;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
public enum AudioSource {
|
||||
OUTPUT("output"),
|
||||
MIC("mic"),
|
||||
PLAYBACK("playback");
|
||||
OUTPUT("output", MediaRecorder.AudioSource.REMOTE_SUBMIX),
|
||||
MIC("mic", MediaRecorder.AudioSource.MIC),
|
||||
PLAYBACK("playback", -1);
|
||||
|
||||
private final String name;
|
||||
private final int directAudioSource;
|
||||
|
||||
AudioSource(String name) {
|
||||
AudioSource(String name, int directAudioSource) {
|
||||
this.name = name;
|
||||
this.directAudioSource = directAudioSource;
|
||||
}
|
||||
|
||||
public boolean isDirect() {
|
||||
return this != PLAYBACK;
|
||||
}
|
||||
|
||||
public int getDirectAudioSource() {
|
||||
return directAudioSource;
|
||||
}
|
||||
|
||||
public static AudioSource findByName(String name) {
|
||||
for (AudioSource audioSource : AudioSource.values()) {
|
||||
if (name.equals(audioSource.name)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue