简体   繁体   English

Android录音和播放+免提电话作为选项

[英]Android recording and playing +speakerphone as an option

I am programming a sip application for Android. 我正在为Android编写一个sip应用程序。 During a call I must record the microphone input and play the incoming audio. 在通话期间,我必须录制麦克风输入并播放传入的音频。 There must be an optional using of speakerphone. 必须有扬声器电话的可选使用。 It must be Android 1.5+ (1.5, 1.6, 2.0, 2.1, 2.2, future versions) compatible and device portable. 它必须兼容Android 1.5+(1.5,1.6,2.0,2.1,2.2,未来版本)和便携设备。

OK. 好。 So I am using AudioTrack to play incoming audio, AudioRecord to record data from the microphone and AudioManager.setSpeakerphoneOn() to enable or disable speakerphone. 所以我使用AudioTrack播放传入的音频,AudioRecord用于记录麦克风的数据,AudioManager.setSpeakerphoneOn()用于启用或禁用免提电话。

Sounds simple but it is not as simple as it should be. 听起来很简单,但并不像应该的那样简单。 AudioManager.setSpeakerphoneOn(false) does not work unless AudioManager.setMode(AudioManager.MODE_IN_CALL) is called. 除非调用AudioManager.setMode(AudioManager.MODE_IN_CALL),否则AudioManager.setSpeakerphoneOn(false)不起作用。 So I have to be in MODE_IN_CALL. 所以我必须在MODE_IN_CALL。

Still OK and simple and it works on my G1 with Android 1.6, older Samsung phone, emulators, many our customer devices etc. But it does not work everywhere :( 仍然可以,简单,它适用于我的G1与Android 1.6,旧的三星手机,模拟器,许多我们的客户设备等。但它无处不在:(

On Samsung tablet GT-P1000 I get stream of 0, 0, 0, 0, ... as microphone input. 在三星平板电脑GT-P1000上,我得到0,0,0,0 ......的流作为麦克风输入。 I think the same problem is on Motorola phones (customers complain). 我认为同样的问题出现在摩托罗拉手机上(客户抱怨)。 After some test I realised that it is caused by AudioManager.setMode(AudioManager.MODE_IN_CALL). 经过一些测试后,我意识到它是由AudioManager.setMode(AudioManager.MODE_IN_CALL)引起的。 This causes that microphone does not work on some devices. 这会导致麦克风在某些设备上无法使用。 But I have to call it because otherwise I can not disable speakerphone. 但我必须打电话给它,否则我无法禁用扬声器。

Is there a simple way how to make it simple, correct and working? 有一种简单的方法可以使它变得简单,正确和有效吗? And if possible without hell like Sipdroid highly dangerous source code: 如果可能的话,没有像Sipdroid这样高度危险的源代码:

if (RtpStreamReceiver.samsung) {
    AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_IN_CALL);
    am.setMode(AudioManager.MODE_NORMAL);
}

or 要么

 void initMode() {
     samsung = Build.MODEL.contains("SAMSUNG") || Build.MODEL.contains("SPH-") ||
     Build.MODEL.contains("SGH-") || Build.MODEL.contains("GT-");

     if (Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL &&
     (Receiver.pstn_state == null || Receiver.pstn_state.equals("IDLE"))) {
       setMode(AudioManager.MODE_NORMAL); 
 }

Thanks a lot Jan 非常感谢Jan

Try it out........ 试试看........

AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); AudioManager audio =(AudioManager)context.getSystemService(Context.AUDIO_SERVICE); audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM