Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: MediaPlayer setVolume function not working

I am trying to play sound via media player on STREAM_SYSTEM

using

mediaPlayer.setVolume(1.0f , 1.0f);

or

mediaPlayer.setVolume(0.90f , 0.90f);

But it is playing on vol as per Hardware volume controls in settings.

Basically this line has no effect.

I have added

permissions "Modify..." as well in Manifest

But i saw links in stackoverflow where this API works.

I don't wanna go to API

AudioManager.setStreamVol()....

as it sets stream vol for all apps

What is problem that this setVol API is not working??

Can anybody give a link to working sample??

like image 420
Rohit Singhal Avatar asked Jan 22 '15 11:01

Rohit Singhal


1 Answers

I faced the same issue. I thought that if I use 0.5f as parameter, I could tell the difference. I tried 0.2f, still no difference. So I thought there was a problem indeed. I finally tried 0.02f just in case, and finally I had a lower volume.

Sample:

replace your

mediaPlayer.setVolume(0.90f , 0.90f);

with

mediaPlayer.setVolume(0.09f , 0.09f);
like image 113
Georges Avatar answered Sep 30 '22 05:09

Georges