示例#1
22
 protected void updateValues() {
   if (timeProgress != null && timeSlider != null && volumeSlider != null) {
     Platform.runLater(
         () -> {
           Duration currentTime = mp.getCurrentTime();
           timeProgress.setText(formatTime(currentTime, duration));
           timeSlider.setDisable(duration.isUnknown());
           if (!timeSlider.isDisabled()
               && duration.greaterThan(Duration.ZERO)
               && !timeSlider.isValueChanging()) {
             timeSlider.setValue(mp.getCurrentTime().divide(duration).toMillis() * 100.0);
             progressBar.setProgress(timeSlider.getValue() / 100);
           }
           if (!volumeSlider.isValueChanging()) {
             volumeSlider.setValue(mp.getVolume());
             if (mp.getVolume() == 0.0) {
               volumeButton.setImage(new Image("icon/Volume_button/mute.png"));
             } else {
               volumeButton.setImage(new Image("icon/Volume_button/volume.png"));
             }
           }
         });
   }
 }
示例#2
0
 void stop(Runnable callback) {
   if (player != null) {
     new Tween(player.getVolume())
         .tweenToZero(
             0.06,
             10L,
             (curVolume) -> {
               player.setVolume(curVolume);
             },
             (zeroVolume) -> {
               isPlaying = false;
               try {
                 if (currentAudioIn != null) {
                   currentAudioIn.close();
                 }
                 player.stop();
                 callback.run();
               } catch (IOException | IllegalStateException | NullPointerException ex) {
                 log.log(Level.ERROR, null, ex);
               }
             });
   } else {
     callback.run();
   }
 }
示例#3
0
 @Override
 public void mute() {
   try {
     savedVolume = myMusician.getVolume();
     myMusician.setVolume(MUTED);
   } catch (Exception e) {
     /* does nothing if myMusician is not initialized */
   }
 }
示例#4
0
 void pause(Runnable callback) {
   if (player != null) {
     new Tween(player.getVolume())
         .tweenToZero(
             0.06,
             10L,
             (curVolume) -> {
               player.setVolume(curVolume);
             },
             (zeroVolume) -> {
               player.pause();
               callback.run();
             });
     isPlaying = false;
   } else {
     callback.run();
   }
 }
示例#5
0
 void resume(Runnable callback) {
   if (player != null) {
     player.setVolume(0d);
     player.play();
     new Tween(player.getVolume())
         .tweenToValue(
             Settings.currentVolume,
             0.06,
             10L,
             (currentVolume) -> {
               player.setVolume(currentVolume);
             },
             (valueVolume) -> {
               player.setVolume(valueVolume);
               callback.run();
             });
     isPlaying = true;
   } else {
     callback.run();
   }
 }