Play audio trough phone speaker of an android device

我只是一个虾纸丫 提交于 2019-12-22 07:00:12

问题


Is it possible to play audio trough the phone speaker of an android device? The smaller speaker inside a phone that produces a low volume sound which can only be heard when listing closely with your ear against the phone.

Hopefully my description is clear enough to understand my question.

If it is possible, a example for how to accomplish this would be really helpful.

EDIT Currently i'm using the following code to initialize my MediaPlayer.

 mediaPlayer = new MediaPlayer();
 mediaPlayer.setOnBufferingUpdateListener(this); 
 mediaPlayer.setOnCompletionListener(this);
 mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
 mediaPlayer.setDataSource(audioPath);
 mediaPlayer.prepare();

回答1:


If you want to play audio through the earpiece, use the STREAM_VOICE_CALL stream type. If you use the MediaPlayer class there's a setAudioStreamType method that you can use for this purpose, and for the AudioTrack class you pass the stream type to the constructor.



来源:https://stackoverflow.com/questions/19771905/play-audio-trough-phone-speaker-of-an-android-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!