Im trying to implement fade in effect to my mp3 player. I´m using FloatControl volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); because FloatControl.Type.VOLUME throws an exception(Unavaliable Control) I dont know why. I need some help with the algorithm, because its not working ok. Heres the code:
public class FloatControlFader
{
public static void fadeIn(final FloatControl control, final float from,
final float to, final int seconds)
{
final float vps = ((to-from) / (seconds*10));//Volume incrased/100millisecond
control.setValue(from);
Thread t = new Thread(new Runnable(){
public void run() {
for(int i=0; i < seconds*10; i++)
{
try
{
Thread.sleep(100);
}
catch (InterruptedException ex)
{
}
System.out.println(control.getValue()); //for DEBUG
control.setValue(control.getValue() + vps);
}
}
});
t.start();
}
}
Would appreciate any help, thanks!