Luciano
Luciano

Reputation: 2798

Play audio trough phone speaker of an android device

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

Upvotes: 5

Views: 6653

Answers (1)

Michael
Michael

Reputation: 58427

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.

Upvotes: 6

Related Questions