Throw AudioCaptureException on workaround error

Replace a RuntimeException by a specific AudioCaptureException.

PR #5102 <https://github.com/Genymobile/scrcpy/pull/5102>
This commit is contained in:
Romain Vimont 2024-07-16 20:00:46 +02:00
parent 3b8ec0c38d
commit cf09e78323
2 changed files with 6 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.genymobile.scrcpy;
import com.genymobile.scrcpy.audio.AudioCaptureException;
import com.genymobile.scrcpy.util.Ln;
import android.annotation.SuppressLint;
@ -195,7 +196,8 @@ public final class Workarounds {
@TargetApi(Build.VERSION_CODES.R)
@SuppressLint("WrongConstant,MissingPermission")
public static AudioRecord createAudioRecord(int source, int sampleRate, int channelConfig, int channels, int channelMask, int encoding) {
public static AudioRecord createAudioRecord(int source, int sampleRate, int channelConfig, int channels, int channelMask, int encoding) throws
AudioCaptureException {
// Vivo (and maybe some other third-party ROMs) modified `AudioRecord`'s constructor, requiring `Context`s from real App environment.
//
// This method invokes the `AudioRecord(long nativeRecordInJavaObj)` constructor to create an empty `AudioRecord` instance, then uses
@ -336,8 +338,8 @@ public final class Workarounds {
return audioRecord;
} catch (Exception e) {
Ln.e("Failed to invoke AudioRecord.<init>.", e);
throw new RuntimeException("Cannot create AudioRecord");
Ln.e("Cannot create AudioRecord", e);
throw new AudioCaptureException();
}
}
}

View File

@ -109,7 +109,7 @@ public final class AudioCapture {
}
}
private void startRecording() {
private void startRecording() throws AudioCaptureException {
try {
recorder = createAudioRecord(audioSource);
} catch (NullPointerException e) {