Browse Source

added a "next episode" button to the player

pull/12/head
Jannik 4 years ago
parent
commit
a677abc15c
  1. 4
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  2. 89
      src/main/java/kellerkinder/HomeFlix/player/PlayerController.java
  3. 13
      src/main/resources/fxml/PlayerWindow.fxml

4
src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java

@ -473,7 +473,7 @@ public class MainWindowController {
while ((line = input.readLine()) != null) {
output = line;
}
LOGGER.info(output);
LOGGER.info("which vlc: " + output);
input.close();
} catch (IOException e1) {
e1.printStackTrace();
@ -604,8 +604,6 @@ public class MainWindowController {
* add data from films-list to films-table
*/
public void addFilmsToTable(ObservableList<FilmTabelDataType> elementsList) {
System.out.println(elementsList.size());
for (FilmTabelDataType element : elementsList) {

89
src/main/java/kellerkinder/HomeFlix/player/PlayerController.java

@ -52,24 +52,18 @@ import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
public class PlayerController {
@FXML
private MediaView mediaView;
@FXML private MediaView mediaView;
@FXML
private VBox bottomVBox;
@FXML private VBox bottomVBox;
@FXML
private HBox controlsHBox;
@FXML private HBox controlsHBox;
@FXML
private JFXSlider timeSlider;
@FXML private JFXSlider timeSlider;
@FXML
private JFXButton stopBtn;
@FXML
private JFXButton playBtn;
@FXML
private JFXButton fullscreenBtn;
@FXML private JFXButton stopBtn;
@FXML private JFXButton playBtn;
@FXML private JFXButton fullscreenBtn;
@FXML private JFXButton nextEpBtn;
private Player player;
private MainWindowController mainWCon;
@ -81,6 +75,9 @@ public class PlayerController {
private double seekTime = 0;
private double startTime = 0;
private double duration = 0;
private int season = 0;
private int episode = 0;
private int countdown = 0;
private boolean mousePressed = false;
private boolean showControls = true;
private boolean autoplay;
@ -123,6 +120,10 @@ public class PlayerController {
width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
season = !film.getSeason().isEmpty() ? Integer.parseInt(film.getSeason()) : 0;
episode = !film.getEpisode().isEmpty() ? Integer.parseInt(film.getEpisode()) : 0;
// nextEpBtn.setStyle("-fx-button-type: RAISED; -fx-background-color: #" + mainWCon.getColor() + "; -fx-text-fill: WHITE;");
// start the media if the player is ready
mediaPlayer.setOnReady(new Runnable() {
@Override
@ -141,27 +142,40 @@ public class PlayerController {
@Override
public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {
currentTime = newValue.toMillis(); // set the current time
int episode = !film.getEpisode().isEmpty() ? Integer.parseInt(film.getEpisode()) : 0;
int season = !film.getSeason().isEmpty() ? Integer.parseInt(film.getSeason()) : 0;
// if we are end time -10 seconds, do autoplay, if activated
if ((duration - currentTime) < 10000 && episode != 0 && autoplay) {
autoplay = false;
mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time
FilmTabelDataType nextFilm = mainWCon.getDbController().getNextEpisode(film.getTitle(), episode, season);
if (nextFilm != null) {
mediaPlayer.stop();
init(mainWCon, player, nextFilm);
autoplay = true;
double timeToEnd = (duration - currentTime);
if (timeToEnd < 20000 && episode != 0 && autoplay) {
// show 20 seconds before the end a button (next episode in 10 seconds)
if(!nextEpBtn.isVisible())
nextEpBtn.setVisible(true);
if(countdown != (int)((timeToEnd -10000) / 1000)) {
countdown = (int)((timeToEnd -10000) / 1000);
nextEpBtn.setText("next episode in " + countdown + " seconds"); // TODO translate
bottomVBox.setVisible(true);
}
// if we are end time -10 seconds, do autoplay, if activated
if(timeToEnd < 10000){
nextEpBtn.setVisible(false);
autoPlayNewFilm();
}
} else if ((duration - currentTime) < 120) {
// if we are -20ms stop the media
} else if (timeToEnd < 120) {
// if we are 120ms to the end stop the media
mediaPlayer.stop();
mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time
playBtn.setGraphic(play_arrow_black);
} else {
if(nextEpBtn.isVisible())
nextEpBtn.setVisible(false);
}
if (!mousePressed) {
timeSlider.setValue((currentTime / 1000) / 60);
// int sec = (int)(currentTime / 1000);
// int min = (int) TimeUnit.SECONDS.toMinutes(sec);
// int remSec = sec - (int)TimeUnit.MINUTES.toSeconds(min);
// System.out.println("\nTime: " + min + ":" + remSec);
}
}
});
@ -182,7 +196,7 @@ public class PlayerController {
// hide controls timer initialization
final Timer timer = new Timer();
TimerTask controlAnimationTask = null; // task to execute save operation
final long delayTime = 2000; // hide the controls after 2 seconds
final long delayTime = 3000; // hide the controls after 2 seconds
@Override
public void handle(MouseEvent mouseEvent) {
@ -254,7 +268,6 @@ public class PlayerController {
@FXML
void playBtnAction(ActionEvent event) {
if (mediaPlayer.getStatus().equals(Status.PLAYING)) {
mediaPlayer.pause();
playBtn.setGraphic(play_arrow_black);
@ -263,6 +276,22 @@ public class PlayerController {
playBtn.setGraphic(pause_black);
}
}
@FXML
void nextEpBtnAction(ActionEvent event) {
autoPlayNewFilm();
}
private void autoPlayNewFilm() {
autoplay = false;
mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time
FilmTabelDataType nextFilm = mainWCon.getDbController().getNextEpisode(film.getTitle(), episode, season);
if (nextFilm != null) {
mediaPlayer.stop();
init(mainWCon, player, nextFilm);
autoplay = true;
}
}
public MediaPlayer getMediaPlayer() {
return mediaPlayer;

13
src/main/resources/fxml/PlayerWindow.fxml

@ -7,8 +7,9 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?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/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kellerkinder.HomeFlix.player.PlayerController">
<AnchorPane prefHeight="720.0" prefWidth="1280.0" style="-fx-background-color: black;" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kellerkinder.HomeFlix.player.PlayerController">
<children>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
@ -34,5 +35,15 @@
</HBox>
</children>
</VBox>
<JFXButton fx:id="nextEpBtn" onAction="#nextEpBtnAction" style="-fx-background-color: ee3523;" text="next episode in 10 seconds" textFill="WHITE" visible="false" AnchorPane.bottomAnchor="80.0" AnchorPane.rightAnchor="20.0">
<font>
<Font name="System Bold" size="14.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="7.0" left="7.0" right="7.0" top="7.0" />
</padding></JFXButton>
</children>
</AnchorPane>

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close