示例#1
0
 @FXML
 void seek(MouseEvent evt) {
   if (player != null) {
     Duration d = player.getMedia().getDuration();
     double millis = (evt.getX() / loadProgressBar.getWidth()) * d.toMillis();
     Duration s = new Duration(millis);
     player.seek(s);
   }
 }
示例#2
0
 void updatePlayProgress() {
   if (player != null && Tray.stage.isShowing()) {
     Duration d = player.getMedia().getDuration();
     Duration t = player.getCurrentTime();
     loadProgressBar.setProgress(t.toMillis() / d.toMillis());
     timeUpdate++;
     if (timeUpdate == 10) {
       timeUpdate = 0;
       Platform.runLater(
           () -> {
             timeLabel.setText(formatTime(d, t));
           });
     }
   }
 }
示例#3
0
 @Override
 protected double computePrefHeight(double width) {
   return mp.getMedia().getHeight() + mediaBar.prefHeight(width);
 }
示例#4
0
 @Override
 protected double computePrefWidth(double height) {
   return Math.max(mp.getMedia().getWidth(), mediaBar.prefWidth(height));
 }
示例#5
0
  private void onPlay() {
    playButton.setImage(new Image("icon/PlayPause_button/pause.png"));

    mp.setOnReady(
        () -> {
          duration = mp.getMedia().getDuration();
          updateValues();
        });

    mp.currentTimeProperty()
        .addListener(
            (Observable ov) -> {
              Stage stage = (Stage) root.getScene().getWindow();
              if (stage.isFullScreen() == false) {
                full = false;
              }
              updateValues();
            });

    mp.setOnPaused(
        () -> {
          playButton.setImage(new Image("icon/PlayPause_button/play.png"));
        });

    mp.setOnEndOfMedia(
        () -> {
          switch (repeat) {
            case 0:
              if (fileList.size() - 1 == 0) {
                mp.stop();
                mp.seek(mp.getStartTime());
              } else {
                listView.getSelectionModel().selectNext();
              }
              break;

            case 1:
              mp.seek(Duration.ZERO);
              mp.setCycleCount(MediaPlayer.INDEFINITE);
              break;

            case 2:
              if (j == fileList.size() - 1) {
                if (fileList.size() - 1 == 0) {
                  mp.setCycleCount(MediaPlayer.INDEFINITE);
                } else {
                  listView.getSelectionModel().selectFirst();
                }
              } else {
                listView.getSelectionModel().selectNext();
              }
              break;
          }
          atEndOfMedia = true;
        });

    timeSlider
        .valueProperty()
        .addListener(
            (Observable ov) -> {
              if (timeSlider.isValueChanging()) {
                progressBar.setProgress(timeSlider.getValue() / 100);
                mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
              }
            });

    volumeSlider
        .valueProperty()
        .addListener(
            (ObservableValue<? extends Number> ov, Number old_val, Number new_val) -> {
              mp.setVolume(new_val.doubleValue());
              volumeBar.setProgress(new_val.doubleValue());
            });

    play = true;
    volumeSlider.setMouseTransparent(!play);
    timeSlider.setMouseTransparent(!play);
  }