@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); } }
/* * 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); }