平板电脑可以清晰播放收到的音频(语音),但手机播放的音频是噪音.
然后我在平板电脑的代码中设置此音频模式:
audioManager.setMode(AudioManager.MODE_IN_CALL);
这导致移动接收清晰的语音.
但平板电脑变得沉默,它不会播放收到的音频(或者说它听不到).
我不确定我应该在这里使用哪种AudioManager模式组合(如果有的话)?
解决方法 可以将您想要播放的声音处理为闹钟.创建一个名为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();}
我希望这适合你. 总结
以上是内存溢出为你收集整理的Android:应设置什么音频模式以在设备之间发送接收语音全部内容,希望文章能够帮你解决Android:应设置什么音频模式以在设备之间发送接收语音所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)