开发者

Android : Audio file from internal speaker

开发者 https://www.devze.com 2023-02-19 19:52 出处:网络
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. T

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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号