AudioManager setMode (MODE_IN_CALL)를 사용하기 위해 AudioManager를 사용하여 전화가 걸리기 바로 전에 수화기를 통해 소리를 재생합니다.AudioManager MODE_IN_CALL 간섭
음악을 올바르게 재생 한 후 갤럭시 S3를 제외하고 벨소리가 매우 왜곡되고 매우 시끄러운 것처럼 들립니다. 나는 setMode 문서를 읽었다.
The audio mode encompasses audio routing AND the behavior of the telephony
layer. Therefore this method should only be used by applications that replace
the platform-wide management of audio settings or the main telephony application.
In particular, the MODE_IN_CALL mode should only be used by the telephony
application when it places a phone call, as it will cause signals from the
radio layer to feed the platform mixer.
나는 라디오 레이어 급송 플랫폼 믹서로부터 신호가있을 것이라고 생각한다.
그래서 내가 사용 코드는 다음과 같다 : 다음
am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
speakerWasOn = am.isSpeakerphoneOn();
speakerPrevMode = am.getMode();
bthA2dpWasOn = am.isBluetoothA2dpOn();
bthScoWasOn = am.isBluetoothScoOn();
if (BluetoothBR.bthOn && BluetoothBR.conectarBluetooth()) {
am.setMode(AudioManager.STREAM_VOICE_CALL);
am.setBluetoothA2dpOn(true);
am.setBluetoothScoOn(true);
} else {
am.setSpeakerphoneOn(false);
am.setMode(AudioManager.MODE_IN_CALL);
}
내가 분리 된 스레드에 .MP3 파일을 재생 MediaPlayer를를 사용
private OnPreparedListener opl = new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
try {
mp.setVolume(1.0f, 1.0f);
mp.start();
} catch (Throwable e) {
e.printStackTrace();
mp.release();
}
}
};
private OnCompletionListener ocl = new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
stop();
}
};
public void run() {
synchronized (mp) {
FileInputStream fis = null;
try {
fis = new FileInputStream(getMp3FilePath());
mp.setDataSource(fis.getFD());
mp.setOnPreparedListener(opl);
mp.setOnCompletionListener(ocl);
mp.prepare();
fis.close();
} catch (Exception e) {
mp.release();
if (fis != null) {
try {
fis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
}
public void stop() {
if (mp != null) {
try {
mp.stop();
mp.release();
mp.setVolume(0.5f, 0.5f);
mp.reset();
} catch (Exception ignored) {
}
}
if (BluetoothBR.bthOn) {
BluetoothBR.desconectarBluetooth();
}
}
그리고 음악은 내가 이루어집니다 전화 :
am.setSpeakerphoneOn(speakerWasOn);
am.setMode(speakerPrevMode);
am.setBluetoothA2dpOn(bthA2dpWasOn);
am.setBluetoothScoOn(bthScoWasOn);
이 삼성 갤럭시 S3 (AFAIK)와에 무슨 일이 일어나고은 S2, 화웨이, 소니 에릭슨에서 테스트되었습니다 , 그리고 다른 사람들과 올바르게 작동합니다.
어떤 아이디어? 감사
UPDATE : 스레드가 5 초 대기 있다면 모두가 잘 작동 것을 발견했다
때 음악을 완료하고 원래 상태로 AudioManager를 설정 한 후.
am.setSpeakerphoneOn(speakerWasOn);
am.setMode(speakerPrevMode);
am.setBluetoothA2dpOn(bthA2dpWasOn);
am.setBluetoothScoOn(bthScoWasOn);
long ctime = System.currentTimeMillis();
while (System.currentTimeMillis() - ctime < 5000);
STREAM_VOICE_CALL은 모드가 아니며 값은 0이므로 모드를 MODE_NORMAL로 설정하고 있습니다.이 모드도 0입니다. – behelit