From c04a7c0d4d582c2f946711efb3c0ac1f63f31d72 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Fri, 22 May 2020 16:46:46 +0200 Subject: [PATCH] add demo audio track selection popup --- pom.xml | 14 ++-- .../org/mosad/homeflix/application/Main.java | 4 +- .../org/mosad/homeflix/player/Player.java | 4 +- .../homeflix/player/PlayerController.java | 67 ++++++++++++++---- src/main/resources/fxml/PlayerWindow.fxml | 19 +++-- .../icons/baseline_subtitles_white_48dp.png | Bin 0 -> 200 bytes 6 files changed, 80 insertions(+), 28 deletions(-) create mode 100644 src/main/resources/icons/baseline_subtitles_white_48dp.png diff --git a/pom.xml b/pom.xml index 6687e32..71ced54 100644 --- a/pom.xml +++ b/pom.xml @@ -27,25 +27,25 @@ org.openjfx javafx-controls - 14 + 14.0.1 org.openjfx javafx-fxml - 14 + 14.0.1 org.openjfx javafx-media - 14 + 14.0.1 uk.co.caprica vlcj - 4.5.1 + 4.5.2 @@ -69,19 +69,19 @@ org.xerial sqlite-jdbc - 3.30.1 + 3.31.1 org.apache.logging.log4j log4j-api - 2.13.1 + 2.13.3 org.apache.logging.log4j log4j-core - 2.13.1 + 2.13.3 diff --git a/src/main/java/org/mosad/homeflix/application/Main.java b/src/main/java/org/mosad/homeflix/application/Main.java index ffe8215..f902977 100644 --- a/src/main/java/org/mosad/homeflix/application/Main.java +++ b/src/main/java/org/mosad/homeflix/application/Main.java @@ -51,7 +51,7 @@ public class Main extends Application { // TODO rename streamURL to mediaURL @Override - public void start(Stage primaryStage) throws IOException { + public void start(Stage primaryStage) { //initialize the mainWindowController and the primaryStage try { @@ -118,7 +118,7 @@ public class Main extends Application { XMLController.getPosterCache().mkdir(); } - launch(args); + launch(); } } diff --git a/src/main/java/org/mosad/homeflix/player/Player.java b/src/main/java/org/mosad/homeflix/player/Player.java index a03ac2c..25168d5 100644 --- a/src/main/java/org/mosad/homeflix/player/Player.java +++ b/src/main/java/org/mosad/homeflix/player/Player.java @@ -56,7 +56,7 @@ public class Player { */ public Player(String streamURL) { try { - newHFPlayer(streamURL); + defaultPlayer(streamURL); } catch (Exception e) { LOGGER.error("Error while playing media", e); legacyPlayer(streamURL); @@ -67,7 +67,7 @@ public class Player { * start the integrated player * @param streamURL */ - private void newHFPlayer(String mediaURL) { + private void defaultPlayer(String mediaURL) { playerController = new PlayerController(this, mediaURL); try { diff --git a/src/main/java/org/mosad/homeflix/player/PlayerController.java b/src/main/java/org/mosad/homeflix/player/PlayerController.java index a4712bf..4b35584 100644 --- a/src/main/java/org/mosad/homeflix/player/PlayerController.java +++ b/src/main/java/org/mosad/homeflix/player/PlayerController.java @@ -32,6 +32,10 @@ import org.mosad.homeflix.controller.XMLController; import org.mosad.homeflix.datatypes.FilmTabelDataType; import com.jfoenix.controls.JFXButton; +import com.jfoenix.controls.JFXDialogLayout; +import com.jfoenix.controls.JFXPopup; +import com.jfoenix.controls.JFXPopup.PopupHPosition; +import com.jfoenix.controls.JFXPopup.PopupVPosition; import com.jfoenix.controls.JFXSlider; import javafx.application.Platform; @@ -48,9 +52,11 @@ import javafx.scene.image.PixelBuffer; import javafx.scene.image.PixelFormat; import javafx.scene.image.WritableImage; import javafx.scene.input.MouseEvent; +import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.media.MediaView; +import javafx.scene.text.Text; import uk.co.caprica.vlcj.factory.MediaPlayerFactory; import uk.co.caprica.vlcj.player.base.MediaPlayer; import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer; @@ -63,6 +69,7 @@ import uk.co.caprica.vlcj.player.embedded.videosurface.callback.format.RV32Buffe public class PlayerController { + @FXML private AnchorPane panePlayer; @FXML private MediaView mediaView; @FXML private ImageView videoImageView; @@ -77,8 +84,9 @@ public class PlayerController { @FXML private JFXButton btnPlay; @FXML private JFXButton btnReplay; @FXML private JFXButton btnForward; - @FXML private JFXButton fullscreenBtn; - @FXML private JFXButton nextEpBtn; + @FXML private JFXButton btnAudio; + @FXML private JFXButton btnFullscreen; + @FXML private JFXButton btnNextEpisode; @FXML private ImageView stopIcon; @FXML private ImageView playIcon; @@ -141,7 +149,7 @@ public class PlayerController { initPlayerWindow(); initMediaPlayer(); - initSlider(); + initTimeSlider(); } /** @@ -184,9 +192,22 @@ public class PlayerController { }); } + /** + * initialize the embedded media player + */ private void initMediaPlayer() { embeddedMediaPlayer.events().addMediaPlayerEventListener( new HFMediaPlayerEventListener() { + @Override + public void mediaPlayerReady(MediaPlayer mediaPlayer) { + System.out.println(mediaPlayer.audio().trackCount()); + + mediaPlayer.audio().trackDescriptions().forEach(trackDesc -> { + System.out.println(trackDesc.description()); + }); + + } + @Override public void timeChanged(MediaPlayer mediaPlayer, long newTime) { currentTime = newTime; @@ -211,7 +232,10 @@ public class PlayerController { }); } - private void initSlider() { + /** + * initialize the time slider + */ + private void initTimeSlider() { // if the mouse on the timeSlider is released, skip to the new position timeSlider.setOnMouseReleased(new EventHandler() { @Override @@ -228,7 +252,7 @@ public class PlayerController { } }); - // get the new skip time + // on value change, get the new skip time timeSlider.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Number old_val, Number new_val) { @@ -242,6 +266,10 @@ public class PlayerController { embeddedMediaPlayer.controls().skipTime((long) startTime); // skipt to the start time } + /** + * Stop and release the media player. + * Always call this method to stop the media player. + */ public void stop() { DBController.getInstance().setCurrentTime(media.getStreamUrl(), embeddedMediaPlayer.status().time()); embeddedMediaPlayer.controls().stop(); @@ -269,16 +297,16 @@ public class PlayerController { if (endTime < 31000 && episode != 0 && autoplay) { int countdown = (int) ((endTime / 1000) - 20); // a 10 seconds countdown - if (!nextEpBtn.isVisible()) { - nextEpBtn.setVisible(true); + if (!btnNextEpisode.isVisible()) { + btnNextEpisode.setVisible(true); } if (endTime > 20000) { - nextEpBtn.setText(XMLController.getLocalBundle().getString("nextEpisode") + btnNextEpisode.setText(XMLController.getLocalBundle().getString("nextEpisode") + countdown + XMLController.getLocalBundle().getString("seconds")); bottomVBox.setVisible(true); } else { - nextEpBtn.setVisible(false); + btnNextEpisode.setVisible(false); playNextMedia(); } } @@ -312,7 +340,22 @@ public class PlayerController { } @FXML - void fullscreenBtnAction(ActionEvent event) { + void btnAudioAction(ActionEvent event) { + // TODO move to separate class "AudioPopup" + + JFXDialogLayout content = new JFXDialogLayout(); + content.setHeading(new Text("Test")); + content.setBody(new Text("Hallo 123")); + content.setPrefSize(150, 200); + + JFXPopup popup = new JFXPopup(); + popup.setPopupContent(content); + popup.show(btnAudio, PopupVPosition.BOTTOM, PopupHPosition.RIGHT, + 0, -1 * bottomVBox.getHeight()); + } + + @FXML + void btnFullscreenAction(ActionEvent event) { if (player.getStage().isFullScreen()) { player.getStage().setFullScreen(false); fullscreenIcon.setImage(fullscreen); @@ -323,8 +366,8 @@ public class PlayerController { } @FXML - void nextEpBtnAction(ActionEvent event) { - nextEpBtn.setVisible(false); + void btnNextEpisodeAction(ActionEvent event) { + btnNextEpisode.setVisible(false); playNextMedia(); } diff --git a/src/main/resources/fxml/PlayerWindow.fxml b/src/main/resources/fxml/PlayerWindow.fxml index 0f120c4..6b86acd 100644 --- a/src/main/resources/fxml/PlayerWindow.fxml +++ b/src/main/resources/fxml/PlayerWindow.fxml @@ -12,7 +12,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -97,9 +97,18 @@ - + - + + + + + + + + + + @@ -123,7 +132,7 @@ - + diff --git a/src/main/resources/icons/baseline_subtitles_white_48dp.png b/src/main/resources/icons/baseline_subtitles_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..d6cc3e6468b040973ba48c78d559a79dec35f0d9 GIT binary patch literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUteoq(2kP61Pmm68z0z}+DnjbQE z$Y{yG%$CssL;_4EhnyP^SzV?MmC8AAhG4{cH;vLZhbczESQ7(J~cBi^H`k7?q)gj#MF)H u-vLiM(HEz5MGTqUCmmN`pwB-^C3fwz(8h$x8PkAHWAJqKb6Mw<&;$UexJ1za literal 0 HcmV?d00001