Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: MediaPlayer setVolume function

about the params Set what to make the player no sound and full sound

Thanks

like image 544
Qing Avatar asked Mar 07 '11 03:03

Qing


People also ask

How can I stop MediaPlayer in another activity?

You can't destroy one activity from another activity. But you can pause the media player by creating a new instance of MediaPlayer in the second activity and callind the 'stop' method !

How do I turn off MediaPlayer on Android?

The feature is as simple as tapping and holding on the media card of any app then choosing Dismiss.

What is MediaPlayer Android?

MediaPlayer Class in Android is used to play media files. Those are Audio and Video files. It can also be used to play audio or video streams over the network.

Where is the MediaPlayer on Android 13?

A redesigned media player One of the more obvious upgrades you'll see on Android 13, is a redesigned media player widget. It shows up under Quick Settings and on the lock screen when media is playing.


1 Answers

This function is actualy wonderful. Thanks to it you can create a volume scale with any number of steps!

Let's assume you want 50 steps:

int maxVolume = 50; 

Then to set setVolume to any value in this range (0-49) you do this:

float log1=(float)(Math.log(maxVolume-currVolume)/Math.log(maxVolume)); yourMediaPlayer.setVolume(log1,log1); //set volume takes two paramater 

Nice and easy! And DON'T use AudioManager to set volume! It will cause many side effects such as disabling silent mode, which will make your users mad!

like image 146
ssuukk Avatar answered Sep 22 '22 00:09

ssuukk