Пример #1
1
  private void playAudio(Media media) {
    if (mediaView.isVisible() == true) {
      mediaView.setVisible(false);
      display.setVisible(true);
    }
    if (mp != null) {
      mp.dispose();
    }

    mp = new MediaPlayer(media);
    mp.play();

    mp.setAudioSpectrumListener(
        (double timestamp, double duration1, float[] magnitudes, float[] phases) -> {
          display.getChildren().clear();
          int i = 0;
          int x = 10;
          double y = root.getScene().getHeight() / 2;
          Random rand = new Random(System.currentTimeMillis());
          for (float phase : phases) {
            int red = rand.nextInt(255);
            int green = rand.nextInt(255);
            int blue = rand.nextInt(255);
            Circle circle = new Circle(10);
            circle.setCenterX(x + i);
            circle.setCenterY(y + (phase * 100));
            circle.setFill(Color.rgb(red, green, blue, .70));
            display.getChildren().add(circle);
            i += 10;
          }
        });
  }
Пример #2
0
  private void playVideo(Media media) {
    timeProgress.setTextFill(Color.WHITE);
    npView.setVisible(true);
    mView.toBack();
    btnPaFull.setImage(new Image("icon/Full_button/full.png"));
    go = true;

    if (mediaView.isVisible() == false) {
      mediaView.setVisible(true);
      display.setVisible(false);
    }

    if (mp != null) {
      mp.dispose();
    }

    mp = new MediaPlayer(media);
    mediaView.setMediaPlayer(mp);
    mediaView.setPreserveRatio(true);

    final DoubleProperty width = mediaView.fitWidthProperty();
    final DoubleProperty height = mediaView.fitHeightProperty();

    width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
    height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));

    mp.play();
  }
 public void start() {
   movie = new MediaPlayer(path);
   movie.play();
   VIEW.setMediaPlayer(movie);
   movie
       .currentTimeProperty()
       .addListener(
           new ChangeListener<javafx.util.Duration>() {
             @Override
             public void changed(
                 ObservableValue<? extends javafx.util.Duration> observable,
                 javafx.util.Duration duration,
                 javafx.util.Duration current) {
               timeSlider.setValue(current.toSeconds());
             }
           });
   movie.setOnReady(
       new Runnable() {
         @Override
         public void run() {
           timeSlider.setMin(0);
           timeSlider.setValue(0.0);
           timeSlider.setMax(movie.getTotalDuration().toSeconds());
           volumeSlider.setMin(0);
           volumeSlider.setValue(0.5);
         }
       });
   timeSlider.setOnMouseClicked(
       new EventHandler<MouseEvent>() {
         @Override
         public void handle(MouseEvent event) {
           movie.seek(javafx.util.Duration.seconds(timeSlider.getValue()));
         }
       });
   volumeSlider
       .valueProperty()
       .addListener(
           new InvalidationListener() {
             @Override
             public void invalidated(Observable observable) {
               if (volumeSlider.isValueChanging()) {
                 movie.setVolume(volumeSlider.getValue() / 100);
               }
             }
           });
 }
Пример #4
0
 @Override
 protected void layoutChildren() {
   if (mediaView != null && getBottom() != null) {
     mediaView.setFitWidth(getWidth());
     mediaView.setFitHeight(getHeight() - getBottom().prefHeight(-1));
   }
   super.layoutChildren();
   if (mediaView != null && getCenter() != null) {
     mediaView.setTranslateX((((Pane) getCenter()).getWidth() - mediaView.prefWidth(-1)) / 2);
     mediaView.setTranslateY((((Pane) getCenter()).getHeight() - mediaView.prefHeight(-1)) / 2);
   }
 }
Пример #5
0
  /*
   * Constructor for the MediaControl class. Accepts optional parameters from PWS.
   * Creates a visual control bar with a play/pause button, a stop button, and a
   * fullscreen button, which is overlayed onto the MediaPlayer. Also handles
   * entering into the fullscreen viewing mode.
   *
   * @param mp The MediaPlayer object instantiated by the VideoHandler class
   * @param width The PWS optional width for the MediaPlayer
   * @param height The PWS optional height for the MediaPlayer
   * @param loop The PWS optional loop value for the video
   * @param startTime The PWS optional startTime to delay the video starting to play
   * @param playDuration The PWS optional duration to play the video for
   */
  public MediaControl(
      final MediaPlayer mp,
      Integer width,
      Integer height,
      Boolean loop,
      Integer startTime,
      Integer playDuration) {

    this.mp = mp;
    this.startTime = startTime;
    this.playDuration = playDuration;
    mediaView = new MediaView(mp);

    // Retrieve the size of the Screen
    bounds = Screen.getPrimary().getVisualBounds();

    // Assign loop variable as necessary
    if (loop == null) {
      this.mpLoop = false;
    } else {
      this.mpLoop = loop;
    }

    // Set the MediaPlayer cycle count based on the value of loop
    setLoop(mpLoop);

    if (width != null && height != null) {
      // Set the height and width of the MediaPlayer based on the values
      this.mpWidth = width;
      this.mpHeight = height;
      mediaView.setPreserveRatio(false);
      mediaView.setFitWidth(mpWidth);
      mediaView.setFitHeight(mpHeight - 35);
    } else {
      // Set a default size of the MediaPlayer when no height and width are being indicated
      this.mpWidth = (int) (bounds.getWidth() / 2);
      this.mpHeight = (int) (bounds.getHeight() / 4);
      mediaView.setPreserveRatio(true);
      mediaView.setFitWidth(mpWidth);
    }

    if (startTime == null) {
      // Set start time to be 0 when no startTime is being indicated
      this.startTime = 0;
      new Thread(startTimerThread).start();
    } else {
      // Start the startTimerThread based on the startTime indicated
      new Thread(startTimerThread).start();
    }

    // A VBox that contains the MediaView and Control Panel of the MediaPlayer
    overallBox = new VBox();
    overallBox.setMaxSize(mpWidth, mpHeight);
    mediaView.setFitHeight(mpHeight - 35);
    overallBox.getChildren().add(mediaView);

    // A HBox that contains all the Controls of the MediaPlayer
    mediaBar = new HBox();
    mediaBar.setMaxWidth(mpWidth);
    mediaBar.setPadding(new Insets(5, 10, 5, 10));

    try {
      // Get and load images for buttons on MediaControl bar.
      inputStream = new FileInputStream("../Resources/play.png");
      playImage = new Image(inputStream);
      inputStream = new FileInputStream("../Resources/pause.png");
      pauseImage = new Image(inputStream);
      inputStream = new FileInputStream("../Resources/stop.png");
      stopImage = new Image(inputStream);
      inputStream = new FileInputStream("../Resources/fullscreen.png");
      fullscreenImage = new Image(inputStream);
    } catch (FileNotFoundException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    // Handle the play button
    setPlayButton();

    // Handle the stop button
    setStopButton();

    // Handle the fullscreen button
    setFullScreenButton();

    // Label to show the length of the video
    Label timeLabel = new Label("   Time: ");
    timeLabel.setTextFill(Color.WHITE);
    timeLabel.setMinWidth(Control.USE_PREF_SIZE);
    mediaBar.getChildren().add(timeLabel);

    // Handle the time slider
    setTimeSlider();

    // Label to show the current time position of the video
    playTime = new Label();
    playTime.setMinWidth(50);
    playTime.setTextFill(Color.WHITE);
    mediaBar.getChildren().add(playTime);

    // Label to show the current volume of the media
    Label volumeLabel = new Label(" Vol: ");
    volumeLabel.setTextFill(Color.WHITE);
    volumeLabel.setMinWidth(Control.USE_PREF_SIZE);
    mediaBar.getChildren().add(volumeLabel);

    // Handle the volume slider
    setVolumeSlider();

    // Label for play time in full screen mode
    playTimeFS = new Label();
    playTimeFS.setMinWidth(50);
    playTimeFS.setTextFill(Color.WHITE);

    // Add components to Control Panel during fullscreen mode
    fullscreenMediaBar = new HBox();
    fullscreenMediaBar.getChildren().add(playButtonFS);
    fullscreenMediaBar.getChildren().add(timeSliderFS);
    fullscreenMediaBar.getChildren().add(playTimeFS);
    fullscreenMediaBar.setLayoutY(bounds.getHeight() - 20);

    // Add the mediaBar "box" to the overall MediaControl "bar"
    overallBox.getChildren().add(mediaBar);
  }