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