Android : Audio file from internal speaker
I wan开发者_StackOverflow中文版t to play a audio file from the internal speaker (that from which comes the voice during a call) it's possibile ?
Use the setSpeakerphoneOn method of the AudioManager. This requires the MODIFY_AUDIO_SETTINGS permission.
audioManager = (AudioManager)Context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(false);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
Question is a bit old. Anyhow, this method may help others:
public void play(MediaPlayer player, String filePath){
try {
player.setDataSource(filePath);
player.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
player.prepare();
player.start();
} catch (IOException e) {
e.printStackTrace();
}
}
精彩评论