From 6a2a1aaba2be7e0efd868646c05c4b448e099f77 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Thu, 29 Nov 2018 13:36:23 +0100 Subject: [PATCH] Remove HLS player stuff --- client/src/test/java/AudioTest.java | 19 -- client/src/test/java/HlsTest.java | 44 --- client/src/test/java/MediaControl.java | 355 ------------------------- client/src/test/java/pausebutton.png | Bin 107 -> 0 bytes client/src/test/java/playbutton.png | Bin 131 -> 0 bytes 5 files changed, 418 deletions(-) delete mode 100644 client/src/test/java/AudioTest.java delete mode 100644 client/src/test/java/HlsTest.java delete mode 100644 client/src/test/java/MediaControl.java delete mode 100644 client/src/test/java/pausebutton.png delete mode 100644 client/src/test/java/playbutton.png diff --git a/client/src/test/java/AudioTest.java b/client/src/test/java/AudioTest.java deleted file mode 100644 index 78a9ab5e..00000000 --- a/client/src/test/java/AudioTest.java +++ /dev/null @@ -1,19 +0,0 @@ -import javafx.application.Application; -import javafx.application.Platform; -import javafx.scene.media.AudioClip; -import javafx.stage.Stage; - -public class AudioTest extends Application { - - @Override - public void start(Stage primaryStage) throws Exception { - AudioClip clip = new AudioClip("file:///tmp/Oxygen-Im-Highlight-Msg.mp3"); - clip.cycleCountProperty().set(3); - clip.play(); - Platform.exit(); - } - - public static void main(String[] args) { - launch(args); - } -} diff --git a/client/src/test/java/HlsTest.java b/client/src/test/java/HlsTest.java deleted file mode 100644 index d9c06e87..00000000 --- a/client/src/test/java/HlsTest.java +++ /dev/null @@ -1,44 +0,0 @@ -import javafx.application.Application; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.media.Media; -import javafx.scene.media.MediaPlayer; -import javafx.stage.Stage; - -public class HlsTest extends Application { - // media = new Media("http://localhost:3202/hls/sun_shine_baby/2018-11-28_20-43/playlist.m3u8"); - - private static final String MEDIA_URL = "http://localhost:3202/hls/sun_shine_baby/2018-11-28_20-43/playlist.m3u8"; - - private Media media; - private MediaPlayer mediaPlayer; - private MediaControl mediaControl; - - public Parent createContent() { - media = new Media(MEDIA_URL); - mediaPlayer = new MediaPlayer(media); - mediaPlayer.setOnError(()-> { - mediaPlayer.getError().printStackTrace(System.err); - }); - mediaControl = new MediaControl(mediaPlayer); - mediaControl.setMinSize(480, 280); - mediaControl.setPrefSize(480, 280); - mediaControl.setMaxSize(480, 280); - return mediaControl; - } - - @Override - public void start(Stage primaryStage) throws Exception { - primaryStage.setScene(new Scene(createContent())); - primaryStage.show(); - } - - @Override - public void stop() { - mediaPlayer.stop(); - } - - public static void main(String[] args) { - launch(args); - } -} diff --git a/client/src/test/java/MediaControl.java b/client/src/test/java/MediaControl.java deleted file mode 100644 index 55c0e0bb..00000000 --- a/client/src/test/java/MediaControl.java +++ /dev/null @@ -1,355 +0,0 @@ -import javafx.application.Platform; -import javafx.beans.Observable; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.ReadOnlyBooleanProperty; -import javafx.beans.property.ReadOnlyObjectProperty; -import javafx.beans.value.ObservableValue; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; -import javafx.geometry.Insets; -import javafx.geometry.Pos; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Control; -import javafx.scene.control.Label; -import javafx.scene.control.Slider; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.layout.Priority; -import javafx.scene.layout.Region; -import javafx.scene.media.MediaPlayer; -import javafx.scene.media.MediaView; -import javafx.stage.Stage; -import javafx.util.Duration; - -public class MediaControl extends BorderPane { - - private MediaPlayer mp; - private MediaView mediaView; - private final boolean repeat = false; - private boolean stopRequested = false; - private boolean atEndOfMedia = false; - private Duration duration; - private Slider timeSlider; - private Label playTime; - private Slider volumeSlider; - private HBox mediaBar; - private Pane mvPane; - private Stage newStage; - private boolean fullScreen = false; - - @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); - } - } - - @Override - protected double computeMinWidth(double height) { - return mediaBar.prefWidth(-1); - } - - @Override - protected double computeMinHeight(double width) { - return 200; - } - - @Override - protected double computePrefWidth(double height) { - return Math.max(mp.getMedia().getWidth(), mediaBar.prefWidth(height)); - } - - @Override - protected double computePrefHeight(double width) { - return mp.getMedia().getHeight() + mediaBar.prefHeight(width); - } - - @Override - protected double computeMaxWidth(double height) { - return Double.MAX_VALUE; - } - - @Override - protected double computeMaxHeight(double width) { - return Double.MAX_VALUE; - } - - public MediaControl(final MediaPlayer mp) { - this.mp = mp; - setStyle("-fx-background-color: #bfc2c7;"); // TODO: Use css file - mediaView = new MediaView(mp); - mvPane = new Pane(); - mvPane.getChildren().add(mediaView); - mvPane.setStyle("-fx-background-color: black;"); // TODO: Use css file - setCenter(mvPane); - mediaBar = new HBox(5.0); - mediaBar.setPadding(new Insets(5, 10, 5, 10)); - mediaBar.setAlignment(Pos.CENTER_LEFT); - BorderPane.setAlignment(mediaBar, Pos.CENTER); - - final Button playButton = new Button(); - playButton.setMinWidth(Control.USE_PREF_SIZE); - - String PLAY = "playbutton.png"; - String PAUSE = "pausebutton.png"; - Image PlayButton = new Image(getClass().getResourceAsStream(PLAY)); - Image PauseButton = new Image(getClass().getResourceAsStream(PAUSE)); - ImageView imageViewPlay = new ImageView(PlayButton); - ImageView imageViewPause = new ImageView(PauseButton); - playButton.setGraphic(imageViewPlay); - playButton.setOnAction((ActionEvent e) -> { - updateValues(); - MediaPlayer.Status status = mp.getStatus(); - if (status == MediaPlayer.Status.UNKNOWN || status == MediaPlayer.Status.HALTED) { - // don't do anything in these states - return; - } - - if (status == MediaPlayer.Status.PAUSED || status == MediaPlayer.Status.READY || status == MediaPlayer.Status.STOPPED) { - // rewind the movie if we're sitting at the end - if (atEndOfMedia) { - mp.seek(mp.getStartTime()); - atEndOfMedia = false; - playButton.setGraphic(imageViewPlay); - // playButton.setText(">"); - updateValues(); - } - mp.play(); - playButton.setGraphic(imageViewPause); - // playButton.setText("||"); - } else { - mp.pause(); - } - }); - ReadOnlyObjectProperty time = mp.currentTimeProperty(); - time.addListener((ObservableValue observable, Duration oldValue, Duration newValue) -> { - //updateValues(); - }); - mp.setOnPlaying(() -> { - if (stopRequested) { - mp.pause(); - stopRequested = false; - } else { - playButton.setGraphic(imageViewPause); - // playButton.setText("||"); - } - }); - mp.setOnPaused(() -> { - playButton.setGraphic(imageViewPlay); - // playButton.setText("||"); - }); - mp.setOnReady(() -> { - duration = mp.getMedia().getDuration(); - updateValues(); - }); - - mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1); - mp.setOnEndOfMedia(() -> { - if (!repeat) { - playButton.setGraphic(imageViewPlay); - // playButton.setText(">"); - stopRequested = true; - atEndOfMedia = true; - } - }); - mediaBar.getChildren().add(playButton); - - // Time label - Label timeLabel = new Label("Time"); - timeLabel.setMinWidth(Control.USE_PREF_SIZE); - mediaBar.getChildren().add(timeLabel); - - // Time slider - timeSlider = new Slider(); - timeSlider.setMinWidth(30); - timeSlider.setMaxWidth(Double.MAX_VALUE); - HBox.setHgrow(timeSlider, Priority.ALWAYS); - - DoubleProperty timeValue = timeSlider.valueProperty(); - timeValue.addListener((ObservableValue observable, Number old, Number now) -> { - if (timeSlider.isValueChanging()) { - // multiply duration by percentage calculated by slider position - if (duration != null) { - System.out.println(timeSlider.getValue() + "%"); - mp.seek(duration.multiply(timeSlider.getValue() / 100.0)); - } - updateValues(); - } else if (Math.abs(now.doubleValue() - old.doubleValue()) > 1.5) { - // multiply duration by percentage calculated by slider position - System.out.println(timeSlider.getValue() + "%"); - if (duration != null) { - mp.seek(duration.multiply(timeSlider.getValue() / 100.0)); - } - } - }); - mediaBar.getChildren().add(timeSlider); - - // Play label - playTime = new Label(); - playTime.setMinWidth(Control.USE_PREF_SIZE); - - mediaBar.getChildren().add(playTime); - - // Fullscreen button - Button buttonFullScreen = new Button("Full Screen"); - buttonFullScreen.setMinWidth(Control.USE_PREF_SIZE); - - buttonFullScreen.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - if (!fullScreen) { - newStage = new Stage(); - ReadOnlyBooleanProperty full = newStage.fullScreenProperty(); - full.addListener((ObservableValue ov, Boolean old, Boolean now) -> { - onFullScreen(); - }); - final BorderPane borderPane = new BorderPane() { - @Override - protected void layoutChildren() { - if (mediaView != null && getBottom() != null) { - mediaView.setFitWidth(getWidth()); - double height = getHeight() - getBottom().prefHeight(-1); - mediaView.setFitHeight(height); - } - super.layoutChildren(); - if (mediaView != null) { - final Pane center = (Pane) getCenter(); - if (center != null) { // if smaller pane has content - double width = center.getWidth() - mediaView.prefWidth(-1); - double height = center.getHeight() - mediaView.prefHeight(-1); - double xval = width / 2.0; - double yval = height / 2.0; - - mediaView.setTranslateX(xval); - mediaView.setTranslateY(yval); - } - } - } - }; - - setCenter(null); - setBottom(null); - borderPane.setCenter(mvPane); - borderPane.setBottom(mediaBar); - - Scene newScene = new Scene(borderPane); - newStage.setScene(newScene); - // Workaround for disposing stage when exit fullscreen - newStage.setX(-100000); - newStage.setY(-100000); - - newStage.setFullScreen(true); - fullScreen = true; - newStage.show(); - - } else { - // toggle FullScreen - fullScreen = false; - newStage.setFullScreen(false); - - } - } - }); - mediaBar.getChildren().add(buttonFullScreen); - - // Volume label - Label volumeLabel = new Label("Vol"); - volumeLabel.setMinWidth(Control.USE_PREF_SIZE); - mediaBar.getChildren().add(volumeLabel); - - // Volume slider - volumeSlider = new Slider(); - volumeSlider.setPrefWidth(70); - volumeSlider.setMinWidth(30); - volumeSlider.setMaxWidth(Region.USE_PREF_SIZE); - volumeSlider.valueProperty().addListener((Observable ov) -> { - }); - - final DoubleProperty volume = volumeSlider.valueProperty(); - volume.addListener((ObservableValue observable, Number old, Number now) -> { - mp.setVolume(volumeSlider.getValue() / 100.0); - }); - mediaBar.getChildren().add(volumeSlider); - - setBottom(mediaBar); - - } - - protected void onFullScreen() { - if (!newStage.isFullScreen()) { - - fullScreen = false; - BorderPane smallBP = (BorderPane) newStage.getScene().getRoot(); - smallBP.setCenter(null); - setCenter(mvPane); - - smallBP.setBottom(null); - setBottom(mediaBar); - Platform.runLater(() -> { - newStage.close(); - }); - - } - } - - protected void updateValues() { - if (playTime != null && timeSlider != null && volumeSlider != null && duration != null) { - Platform.runLater(() -> { - Duration now = mp.getCurrentTime(); - playTime.setText(formatTime(now, duration)); - timeSlider.setDisable(duration.isUnknown()); - if (!timeSlider.isDisabled() && duration.greaterThan(Duration.ZERO) && !timeSlider.isValueChanging()) { - final double value = now.divide(duration).toMillis() * 100.0; - timeSlider.setValue(value); - } - if (!volumeSlider.isValueChanging()) { - final int value = (int) Math.round(mp.getVolume() * 100); - volumeSlider.setValue(value); - } - }); - } - } - - private String formatTime(Duration elapsed, Duration duration) { - int intElapsed = (int) Math.floor(elapsed.toSeconds()); - int elapsedHours = intElapsed / (60 * 60); - if (elapsedHours > 0) { - intElapsed -= elapsedHours * 60 * 60; - } - int elapsedMinutes = intElapsed / 60; - int elapsedSeconds = intElapsed - elapsedHours * 60 * 60 - elapsedMinutes * 60; - - if (duration.greaterThan(Duration.ZERO)) { - int intDuration = (int) Math.floor(duration.toSeconds()); - int durationHours = intDuration / (60 * 60); - if (durationHours > 0) { - intDuration -= durationHours * 60 * 60; - } - int durationMinutes = intDuration / 60; - int durationSeconds = intDuration - durationHours * 60 * 60 - durationMinutes * 60; - - if (durationHours > 0) { - return String.format("%d:%02d:%02d/%d:%02d:%02d", elapsedHours, elapsedMinutes, elapsedSeconds, durationHours, durationMinutes, - durationSeconds); - } else { - return String.format("%02d:%02d/%02d:%02d", elapsedMinutes, elapsedSeconds, durationMinutes, durationSeconds); - } - } else { - if (elapsedHours > 0) { - return String.format("%d:%02d:%02d", elapsedHours, elapsedMinutes, elapsedSeconds); - } else { - return String.format("%02d:%02d", elapsedMinutes, elapsedSeconds); - } - } - } -} \ No newline at end of file diff --git a/client/src/test/java/pausebutton.png b/client/src/test/java/pausebutton.png deleted file mode 100644 index 4e429238f487ef59389dfcb4253db0dea852eee6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 107 zcmeAS@N?(olHy`uVBq!ia0vp^;y^6G!3HG%>OYYHQbwLGjv*Ddk`pBQ9@q=1x%OEc z=9jfOYYHQeK`ejv*Ddk`pBQ9@vXqKK8-6 zo$v4Rsj3Nw6KC9-wm`x!*L#DMpRV@@slGJMmu=UtUKKoIVmRkf!ot>t5xmQ*f|j%{ gEIIkFS(<^NtY>|`;_-dAfu=Hey85}Sb4q9e0H2015&!@I