示例#1
0
 public void setVolume(int instanceNumber, double volume) {
   if (volumeControl.get(instanceNumber) != null) {
     volumeControl.get(instanceNumber).breakFade();
   }
   float vol = HSvolume.calcVol(volume);
   FloatControl gc = gainControl.get(instanceNumber);
   gc.setValue((float) vol);
 }
示例#2
0
 public int newPlayFromVolume(double vol) {
   final int ouri = clips.size();
   streams.add(null);
   try {
     streams.set(streams.size() - 1, AudioSystem.getAudioInputStream(file));
   } catch (Exception e) {
     e.printStackTrace();
   }
   AudioFormat format = streams.get(streams.size() - 1).getFormat();
   clips.add(null);
   DataLine.Info info = new DataLine.Info(Clip.class, format);
   try {
     clips.set(ouri, (Clip) AudioSystem.getLine(info));
   } catch (Exception e) {
     e.printStackTrace();
   }
   try {
     clips.get(ouri).open(streams.get(streams.size() - 1));
   } catch (Exception e) {
     e.printStackTrace();
   }
   float volume = HSvolume.calcVol(vol);
   gainControl.add((FloatControl) clips.get(ouri).getControl(FloatControl.Type.MASTER_GAIN));
   volumeControl.add(null);
   gainControl.get(gainControl.size() - 1).setValue(volume);
   clips.get(ouri).loop(0);
   clips
       .get(ouri)
       .addLineListener(
           new LineListener() {
             public void update(LineEvent myLineEvent) {
               if (myLineEvent.getType() == LineEvent.Type.STOP
                   || myLineEvent.getType() == LineEvent.Type.CLOSE) clips.get(ouri).close();
               try {
                 streams.get(ouri).close();
               } catch (IOException e) {
                 e.printStackTrace();
               }
             }
           });
   return ouri;
 }