本文整理了Java中javax.sound.sampled.Clip.getControl()
方法的一些代码示例,展示了Clip.getControl()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clip.getControl()
方法的具体详情如下:
包路径:javax.sound.sampled.Clip
类名称:Clip
方法名:getControl
暂无
代码示例来源:origin: chatty/chatty
private static FloatControl getFirstAvailableControl(Clip clip,
FloatControl.Type... types) {
for (FloatControl.Type type : types) {
if (clip.isControlSupported(type)) {
return (FloatControl)clip.getControl(type);
}
}
return null;
}
代码示例来源:origin: com.github.bloodshura/shurax-assets
@Nullable
public FloatControl getGainControl() {
if (gainSupported()) {
return (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
}
return null;
}
代码示例来源:origin: stackoverflow.com
public static void setVolume(Clip clip, int level) {
Objects.requireNonNull(clip);
FloatControl volume = (FloatControl) clip.getControl(FloatControl.Type.VOLUME);
if (volume != null) {
volume.setValue(level / 100.0);
}
}
代码示例来源:origin: com.github.bloodshura/shurax-assets
@Nullable
public FloatControl getPitchControl() {
if (pitchSupported()) {
return (FloatControl) clip.getControl(FloatControl.Type.SAMPLE_RATE);
}
return null;
}
代码示例来源:origin: redomar/JavaGame
public void setVolume(float velocity){
FloatControl volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(velocity);
}
代码示例来源:origin: stackoverflow.com
Clip clipA = AudioSystem.getClip();
Clip clipB = AudioSystem.getClip();
clipA.open(aisA);
clipB.open(aisB);
for (int i = 0; i < 100; i ++) {
FloatControl gainControlA = (FloatControl) clipA.getControl(FloatControl.Type.MASTER_GAIN);
gainControlA.setValue(i * -1f);
FloatControl gainControlB = (FloatControl) clipB.getControl(FloatControl.Type.MASTER_GAIN);
gainControlB.setValue(-100f + i);
Thread.sleep(100);
}
代码示例来源:origin: stackoverflow.com
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(new File("MyClip.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
FloatControl volumeControl =
(FloatControl) clip.getControl(FloatControl.Type.VOLUME);
volumeControl.setValue(10.0f); // Increase volume by 10 decibels.
clip.start();
代码示例来源:origin: stackoverflow.com
public void playSound(String soundLoc)
{
try
{
InputStream inputStream = getClass().getResourceAsStream(soundLoc);
AudioStream audioStream = new AudioStream(inputStream);
AudioPlayer.player.start(audioStream);
Clip myclip = AudioSystem.getClip();
myclip.open(audioStream);
FloatControl audioControl = (FloatControl) myclip.getControl(FloatControl.Type.MASTER_GAIN);
audioControl.setValue(-5.0f); //decrease volume 5 decibels
clip.start();
}//end try
catch (Exception e)
{
}//end catch
}//end playSound method
代码示例来源:origin: nroduit/Weasis
void addSampledControls() {
try {
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
if (gainControl != null) {
this.add(createSlider(gainControl));
}
} catch (IllegalArgumentException e) {
// If MASTER_GAIN volume control is unsupported, just skip it
}
try {
// FloatControl.Type.BALANCE is probably the correct control to
// use here, but it doesn't work for me, so I use PAN instead.
FloatControl panControl = (FloatControl) clip.getControl(FloatControl.Type.PAN);
if (panControl != null) {
this.add(createSlider(panControl));
}
} catch (IllegalArgumentException e) {
}
}
代码示例来源:origin: stackoverflow.com
public static void play(Clip clip) {
if (Settings.getSettings().isVolumeOn()) {
FloatControl control = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
int volume = Settings.getSettings().getVolume();
float range = control.getMinimum();
float result = range * (1 - volume / 100.0f);
control.setValue(result);
clip.start();
}
}
代码示例来源:origin: Exslims/MercuryTrade
private void play(String wavPath, float db) {
if (!dnd && db > -40) {
ClassLoader classLoader = getClass().getClassLoader();
try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
Clip clip = AudioSystem.getClip();
clip.open(stream);
if (db != 0.0) {
FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(db);
}
clip.start();
} catch (Exception e) {
logger.error("Cannot start playing wav file: ", e);
}
}
}
}
代码示例来源:origin: stackoverflow.com
String filename="foo.wav";
Clip clip=AudioSystem.getClip();
AudioInputStream inputStream=AudioSystem.getAudioInputStream(new BufferedInputStream(Audio.class.getResourceAsStream(filename)));
if(inputStream!=null) {
clip.open(inputStream);
FloatControl gainControl=(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(+6.0f); // ?
clip.start();
// maybe do not wait?
while(clip.getMicrosecondLength()!=clip.getMicrosecondPosition())
Thread.yield(); // wait
// or at least don't wait here?
Thread.sleep(500);
clip.close();
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws Exception {
File in = new File("C:\\Users\\Sandra\\Desktop\\music\\rags.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(in);
Clip play = AudioSystem.getClip();
play.open(audioInputStream);
FloatControl volume= (FloatControl)play.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(1.0f); // Reduce volume by 10 decibels.
play.start();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// A GUI element to prevent the Clip's daemon Thread
// from terminating at the end of the main()
JOptionPane.showMessageDialog(null, "Close to exit!");
}
});
}
代码示例来源:origin: stackoverflow.com
static String randomName = "TreasureQuest";
public static Clip clip = null;
public static void playSound(String name) throws Exception{
if (clip != null && clip.isOpen()) clip.close();
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("music/" + name + ".wav").getAbsoluteFile());
clip = AudioSystem.getClip();
clip.open(audioInputStream);
FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(0f);
System.out.println(clip.getFrameLength() + " | " + clip.getFramePosition());
clip.start();
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws IOException,
UnsupportedAudioFileException, LineUnavailableException
{
File in = new File("C:\\Users\\Sandra\\Desktop\\music\\rags.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(in);
Clip play = AudioSystem.getClip();
play.open(audioInputStream);
FloatControl volume= (FloatControl) play.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(1.0f); // Reduce volume by 10 decibels.
play.start();
play.drain();
play.close();
}
代码示例来源:origin: playn/playn
@Override
protected void setVolumeImpl(float volume) {
if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN);
volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum()));
}
}
代码示例来源:origin: com.googlecode.playn/playn-java
@Override
protected void setVolumeImpl(float volume) {
if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN);
volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum()));
}
}
代码示例来源:origin: UNIVALI-LITE/Portugol-Studio
public Reproducao(File som, Integer endereco) throws ErroExecucaoBiblioteca
{
this.endereco = endereco;
try
{
clip = AudioSystem.getClip();
AudioInputStream stream = criaStream(som);
clip.open(stream);
stream.close();
if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN))
{
controleDeVolume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
}
}
catch (Exception excecao)
{
throw new ErroExecucaoBiblioteca("Não foi possível criar ou abrir uma linha de execução de áudio para " + som.getAbsolutePath());
}
}
代码示例来源:origin: threerings/playn
@Override
protected void setVolumeImpl(float volume) {
if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN);
volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum()));
}
}
代码示例来源:origin: io.playn/playn-java-base
@Override
protected void setVolumeImpl(float volume) {
if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN);
volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum()));
}
}
内容来源于网络,如有侵权,请联系作者删除!