安卓:MediaPlayer的setVolume功能功能、MediaPlayer、setVolume

2023-09-12 03:55:57 作者:终究还是放不开

有关PARAMS 设置了什么让玩家无声音和饱满的声音

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

感谢

推荐答案

这个功能是actualy精彩。多亏了它,你可以创建一个卷的规模与任何数量的步骤!

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

让我们假设你想50步骤:

Let's assume you want 50 steps:

int maxVolume = 50;

然后设置setVolume为任意值在此范围内(0-49)你这样做:

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

尼斯和容易!并且没有使用AudioManager设置音量!这会造成许多副作用,如禁用静音模式,这将使你的用户疯了!

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!