ورود

View Full Version : تغییر volume کارت صدا توسط جاوا



saeedIRHA
دوشنبه 27 آذر 1385, 06:00 صبح
سلام دوستان،
چطور میتونم Volume رو با جا تغییر بدم و کم و زیاد کنم؟؟

saeedIRHA
سه شنبه 28 آذر 1385, 00:12 صبح
خوب ظاهراً یا دوستان نمیدونستن یا حوصله جواب دادن نداشتن،
به هر حال من خودم به یک نتایجی رسیدم کدش رو هم میزارم اینجا:




import javax.sound.sampled.*;
import java.io.*;
//Complete Details: http://forum.java.sun.com/thread.jspa?threadID=576721&start=15
public class Volume
{
static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
static float x;
public static void main(String [] args)
{
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo(); //Bedast ovordan Mixer ha
Mixer myMixer; // more details: http://java.sun.com/docs/books/tutorial/sound/controls.html
String input;
try{
input = stdin.readLine();
int l = Integer.parseInt(input);
x = l/100f;
System.out.println("X= " + x);
}catch(IOException e){System.out.println(e.getMessage());}

for(int i=0;i< mixerInfo.length;i++) //match kardan mixer be etelalate bedast ovordeye mixer ha
{
System.out.println("Mixer Info: " + mixerInfo[i]);
myMixer = AudioSystem.getMixer(mixerInfo[i]);
/*Control[] controls = myMixer.getControls();
System.out.println("--->" + controls.length + "<---");

if(controls.length != 0)
{
System.out.println("[+]" + controls[0]);
}
*/
Line.Info[] targetLineInfo = myMixer.getTargetLineInfo(); //bedast ovordan line haye ghabele estefade
System.out.println("[+]Target Lines: " + targetLineInfo.length);
for(int j=0; j < targetLineInfo.length ; j++)
{
try{
Line.Info lineInfo = targetLineInfo[j]; //Test kardan Line haye bedast omade baraye khoroji
Line line = AudioSystem.getLine(lineInfo); //Conect kardan be Line
line.open();
System.out.println("Is Line Open? [True/False] :" + line.isOpen());
FloatControl c = (FloatControl) line.getControl(FloatControl.Type.VOLUME);
//Bedast ovordan Controller be khoroji line vasl shodeh
c.setValue(x);
line.close();

}
catch(Exception e){
System.out.println("Error: " + e.getMessage());
}
}
}

}

}



*تنها اشکالی که داره اینکه در Linux کار نمیکنه!
اگر راه حلی محبت کنین ممنون میشام!