Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 622
Luciano Avatar asked Nov 04 '13 16:11

Luciano


People also ask

How do I enable speaker output on Android?

Tap the small button at the top right of the player notification tile. In the media player pop-up, you'll see a list of connected audio devices. Tap the one you want to switch to.

Can I use my phone as audio output?

All you need to do is install SoundWire, which is an audio mirroring app on your laptop, as well as your Android. After that, connect the devices to the same WiFi network and set up the app. Tweak settings as required, and you'll be able to stream the audio from your laptop or PC through your phone's speakers.

How do I cast my phone to speaker?

Mirror your Android phone or tablet music From your Android phone or tablet, open the Google Home app. Tap the left hand navigation to open the menu. Tap “Cast screen / audio” and select your speakers.


1 Answers

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.

like image 192
Michael Avatar answered Oct 06 '22 15:10

Michael