Android:应该设置什么audio模式来发送设备之间的接收语音

我正尝试在两个Android设备Tablet和Mobile(通过Java套接字)之间传输语音/audio(双向)。

平板电脑可以清晰地播放接收到的audio(语音),但手机播放收到的audio是噪音。
然后我在平板电脑上的代码中设置这个audio模式:
audioManager.setMode(AudioManager.MODE_IN_CALL);

这现在导致移动接收清晰的声音。 但平板电脑却保持沉默,不会播放收到的audio(或者说听不到)。

我不知道我应该在这里使用的AudioManager模式的组合(如果有的话)?

    Related of "Android:应该设置什么audio模式来发送设备之间的接收语音"

    可以处理您想要作为Alarm播放的声音。

    创build一个名为AlarmController的新类,并尝试使用此代码。

    这对我在Android 4.4.2(华为登顶P7), 每个系统音量(媒体,铃声,闹钟)设置为0。

     Context context; MediaPlayer mp; AudioManager mAudioManager; int userVolume; public AlarmController(Context c) { // constructor for my alarm controller class this.context = c; mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); //remeber what the user's volume was set to before we change it. userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM); mp = new MediaPlayer(); } public void playSound(String soundURI){ Uri alarmSound = null; Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); try{ alarmSound = Uri.parse(soundURI); }catch(Exception e){ alarmSound = ringtoneUri; } finally{ if(alarmSound == null){ alarmSound = ringtoneUri; } } try { if(!mp.isPlaying()){ mp.setDataSource(context, alarmSound); mp.setAudioStreamType(AudioManager.STREAM_ALARM); mp.setLooping(true); mp.prepare(); mp.start(); } } catch (IOException e) { Toast.makeText(context, "Your alarm sound was unavailable.", Toast.LENGTH_LONG).show(); } // set the volume to what we want it to be. In this case it's max volume for the alarm stream. mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), AudioManager.FLAG_PLAY_SOUND); } public void stopSound(){ // reset the volume to what it was before we changed it. mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, userVolume, AudioManager.FLAG_PLAY_SOUND); mp.stop(); mp.reset(); } public void releasePlayer(){ mp.release(); } 

    我希望这对你有用。 🙂