Browse Source

add demo audio track selection popup

dev
Jannik Seiler 6 days ago
parent
commit
c04a7c0d4d
Signed by: Seil0 <seil0@mosad.xyz> GPG Key ID: E8459F3723C52C24
6 changed files with 80 additions and 28 deletions
  1. +7
    -7
      pom.xml
  2. +2
    -2
      src/main/java/org/mosad/homeflix/application/Main.java
  3. +2
    -2
      src/main/java/org/mosad/homeflix/player/Player.java
  4. +55
    -12
      src/main/java/org/mosad/homeflix/player/PlayerController.java
  5. +14
    -5
      src/main/resources/fxml/PlayerWindow.fxml
  6. BIN
      src/main/resources/icons/baseline_subtitles_white_48dp.png

+ 7
- 7
pom.xml View File

@@ -27,25 +27,25 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
<version>14.0.1</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>14</version>
<version>14.0.1</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>14</version>
<version>14.0.1</version>
</dependency>

<dependency>
<groupId>uk.co.caprica</groupId>
<artifactId>vlcj</artifactId>
<version>4.5.1</version>
<version>4.5.2</version>
</dependency>

<dependency>
@@ -69,19 +69,19 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.30.1</version>
<version>3.31.1</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.1</version>
<version>2.13.3</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.1</version>
<version>2.13.3</version>
</dependency>
</dependencies>



+ 2
- 2
src/main/java/org/mosad/homeflix/application/Main.java View File

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

}

+ 2
- 2
src/main/java/org/mosad/homeflix/player/Player.java View File

@@ -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 {


+ 55
- 12
src/main/java/org/mosad/homeflix/player/PlayerController.java View File

@@ -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<MouseEvent>() {
@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<Number>() {
@Override
public void changed(ObservableValue<? extends Number> 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();
}


+ 14
- 5
src/main/resources/fxml/PlayerWindow.fxml View File

@@ -12,7 +12,7 @@
<?import javafx.scene.media.MediaView?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="720.0" prefWidth="1280.0" style="-fx-background-color: black;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane fx:id="panePlayer" prefHeight="720.0" prefWidth="1280.0" style="-fx-background-color: black;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
@@ -65,7 +65,7 @@
<children>
<HBox spacing="10.0">
<children>
<JFXButton fx:id="btnPlay" buttonType="RAISED" contentDisplay="GRAPHIC_ONLY" onAction="#btnPlayAction">
<JFXButton fx:id="btnPlay" contentDisplay="GRAPHIC_ONLY" onAction="#btnPlayAction">
<graphic>
<ImageView fx:id="playIcon" fitHeight="42.0" pickOnBounds="true" preserveRatio="true">
<image>
@@ -97,9 +97,18 @@
<Insets left="5.0" right="5.0" />
</padding>
</HBox>
<HBox alignment="TOP_RIGHT" HBox.hgrow="ALWAYS">
<HBox alignment="TOP_RIGHT" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<JFXButton fx:id="fullscreenBtn" buttonType="RAISED" contentDisplay="GRAPHIC_ONLY" onAction="#fullscreenBtnAction" prefHeight="39.0">
<JFXButton fx:id="btnAudio" contentDisplay="GRAPHIC_ONLY" onAction="#btnAudioAction">
<graphic>
<ImageView fitHeight="42.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/baseline_subtitles_white_48dp.png" />
</image>
</ImageView>
</graphic>
</JFXButton>
<JFXButton fx:id="btnFullscreen" contentDisplay="GRAPHIC_ONLY" onAction="#btnFullscreenAction" prefHeight="39.0">
<graphic>
<ImageView fx:id="fullscreenIcon" fitHeight="42.0" pickOnBounds="true" preserveRatio="true">
<image>
@@ -123,7 +132,7 @@
<Insets bottom="5.0" />
</padding>
</VBox>
<JFXButton fx:id="nextEpBtn" onAction="#nextEpBtnAction" style="-fx-background-color: ee3523;" text="next episode in 10 seconds" textFill="WHITE" visible="false" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="20.0">
<JFXButton fx:id="btnNextEpisode" onAction="#btnNextEpisodeAction" style="-fx-background-color: ee3523;" text="next episode in 10 seconds" textFill="WHITE" visible="false" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="20.0">
<font>
<Font name="System Bold" size="14.0" />
</font>


BIN
src/main/resources/icons/baseline_subtitles_white_48dp.png View File

Before After
Width: 48  |  Height: 48  |  Size: 200B

Loading…
Cancel
Save