Alap kéne legyen.
Originally shared by Aladin Q
SeekBar with a logarithmic scale on Android.
A linear volume slider do not match human perception of sound intensity (Psychoacoustics). Consequently, using a SeekBar to properly control a volume in your application requires little extra code.
A SeekBar ranging from 1 to 100 returns value from 1 to 100, linearly (y = x):
1 -- 25 -- 50 -- 75 --> 100
A logarithmic SeekBar ranging from 1 to 100 returns value from 0 to 100:
0 -- 4 -- 20 -- 52 --> 100
This trivial formula y = (x²/200)*log(x) in the OnSeekBarChangeListener listener will allow us to change the default linear SeekBar into a logarithmic one.
---
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int x = progress;
int y = (int) (((x*x)/200)*Math.log10(x));
// Use the value "y" to control a volume level
}
#Android #AndroidDev #SeekBar Audioid
Originally shared by Aladin Q
SeekBar with a logarithmic scale on Android.
A linear volume slider do not match human perception of sound intensity (Psychoacoustics). Consequently, using a SeekBar to properly control a volume in your application requires little extra code.
A SeekBar ranging from 1 to 100 returns value from 1 to 100, linearly (y = x):
1 -- 25 -- 50 -- 75 --> 100
A logarithmic SeekBar ranging from 1 to 100 returns value from 0 to 100:
0 -- 4 -- 20 -- 52 --> 100
This trivial formula y = (x²/200)*log(x) in the OnSeekBarChangeListener listener will allow us to change the default linear SeekBar into a logarithmic one.
---
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int x = progress;
int y = (int) (((x*x)/200)*Math.log10(x));
// Use the value "y" to control a volume level
}
#Android #AndroidDev #SeekBar Audioid
Megjegyzések
Megjegyzés küldése