开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜