use of android.media.AudioRecord in project android_frameworks_base by DirtyUnicorns.
the class MediaAudioEffectTest method test1_1ConstructorFromUuid.
//Test case 1.1: test constructor from effect uuid
@LargeTest
public void test1_1ConstructorFromUuid() throws Exception {
boolean result = true;
String msg = "test1_1ConstructorFromUuid()";
AudioEffect.Descriptor[] desc = AudioEffect.queryEffects();
assertTrue(msg + "no effects found", (desc.length != 0));
try {
int sessionId;
AudioRecord ar = null;
if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) {
ar = getAudioRecord();
sessionId = ar.getAudioSessionId();
} else {
sessionId = 0;
}
AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, desc[0].uuid, 0, sessionId);
assertNotNull(msg + ": could not create AudioEffect", effect);
effect.release();
if (ar != null) {
ar.release();
}
} catch (IllegalArgumentException e) {
msg = msg.concat(": Effect not found: " + desc[0].name);
result = false;
} catch (UnsupportedOperationException e) {
msg = msg.concat(": Effect library not loaded");
result = false;
}
assertTrue(msg, result);
}
use of android.media.AudioRecord in project android_frameworks_base by AOSPA.
the class MediaAudioEffectTest method test1_0ConstructorFromType.
//Test case 1.0: test constructor from effect type and get effect ID
@LargeTest
public void test1_0ConstructorFromType() throws Exception {
boolean result = true;
String msg = "test1_0ConstructorFromType()";
AudioEffect.Descriptor[] desc = AudioEffect.queryEffects();
assertTrue(msg + ": no effects found", (desc.length != 0));
try {
int sessionId;
AudioRecord ar = null;
if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) {
ar = getAudioRecord();
sessionId = ar.getAudioSessionId();
} else {
sessionId = 0;
}
AudioEffect effect = new AudioEffect(desc[0].type, AudioEffect.EFFECT_TYPE_NULL, 0, sessionId);
assertNotNull(msg + ": could not create AudioEffect", effect);
try {
assertTrue(msg + ": invalid effect ID", (effect.getId() != 0));
} catch (IllegalStateException e) {
msg = msg.concat(": AudioEffect not initialized");
result = false;
} finally {
effect.release();
if (ar != null) {
ar.release();
}
}
} catch (IllegalArgumentException e) {
msg = msg.concat(": Effect not found: " + desc[0].name);
result = false;
} catch (UnsupportedOperationException e) {
msg = msg.concat(": Effect library not loaded");
result = false;
}
assertTrue(msg, result);
}
use of android.media.AudioRecord in project android_frameworks_base by AOSPA.
the class MediaAudioEffectTest method test1_1ConstructorFromUuid.
//Test case 1.1: test constructor from effect uuid
@LargeTest
public void test1_1ConstructorFromUuid() throws Exception {
boolean result = true;
String msg = "test1_1ConstructorFromUuid()";
AudioEffect.Descriptor[] desc = AudioEffect.queryEffects();
assertTrue(msg + "no effects found", (desc.length != 0));
try {
int sessionId;
AudioRecord ar = null;
if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) {
ar = getAudioRecord();
sessionId = ar.getAudioSessionId();
} else {
sessionId = 0;
}
AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, desc[0].uuid, 0, sessionId);
assertNotNull(msg + ": could not create AudioEffect", effect);
effect.release();
if (ar != null) {
ar.release();
}
} catch (IllegalArgumentException e) {
msg = msg.concat(": Effect not found: " + desc[0].name);
result = false;
} catch (UnsupportedOperationException e) {
msg = msg.concat(": Effect library not loaded");
result = false;
}
assertTrue(msg, result);
}
use of android.media.AudioRecord in project android_frameworks_base by ResurrectionRemix.
the class MediaAudioEffectTest method test1_1ConstructorFromUuid.
//Test case 1.1: test constructor from effect uuid
@LargeTest
public void test1_1ConstructorFromUuid() throws Exception {
boolean result = true;
String msg = "test1_1ConstructorFromUuid()";
AudioEffect.Descriptor[] desc = AudioEffect.queryEffects();
assertTrue(msg + "no effects found", (desc.length != 0));
try {
int sessionId;
AudioRecord ar = null;
if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) {
ar = getAudioRecord();
sessionId = ar.getAudioSessionId();
} else {
sessionId = 0;
}
AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, desc[0].uuid, 0, sessionId);
assertNotNull(msg + ": could not create AudioEffect", effect);
effect.release();
if (ar != null) {
ar.release();
}
} catch (IllegalArgumentException e) {
msg = msg.concat(": Effect not found: " + desc[0].name);
result = false;
} catch (UnsupportedOperationException e) {
msg = msg.concat(": Effect library not loaded");
result = false;
}
assertTrue(msg, result);
}
use of android.media.AudioRecord in project LshUtils by SenhLinsh.
the class LshPermissionUtils method hasRecordPermissionBeforeAndroidM.
public static boolean hasRecordPermissionBeforeAndroidM() {
try {
boolean hasPermission = true;
AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, 1024 * 2);
//开始录制音频
try {
// 防止某些手机崩溃,例如联想
audioRecord.startRecording();
} catch (IllegalStateException e) {
e.printStackTrace();
}
// 根据开始录音判断是否有录音权限
if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
hasPermission = false;
}
audioRecord.stop();
audioRecord.release();
return hasPermission;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
Aggregations