Томас Петр Томас Петр - 1 year ago 99
Android Question

Android: MediaPlayer - handsfree volume

I'm trying to manually disable / enable playback of the audio to a Bluetooth device (handsfree in the car). So I need MediaPlayer set to be played from speakers on the phone ONLY or a speaker Bluetooth device ONLY - BUT of course when Bluetooth device are connected - if not, I want to use phone speaker.

I managed to do that only in this way:

AudioManager ax = (AudioManager) getSystemService(AUDIO_SERVICE);

This works great but just when I use this line


When i'm using "false" on this line, the speaker is quietly and I don't want that (but everything else works as it should, just the sound is quietly).

so I want a way to :

  1. play sound from the speakers in the phone (only)

  2. play sound from the bluetooth device (only)

  3. when device is not connected - step 1.

If I'm using different modes, it does not work properly - eg. The sound plays int bluetooth device, but also phone speaker.

Thanks for answers.

Answer Source


   ax.setStreamVolume(AudioManager.MODE_NORMAL, 20, 0);
    // BT enabled - only BT when is connected
    // speaker - when is not connected
    ax.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download