added a "next episode" button to the player
This commit is contained in:
parent
c3a148b267
commit
a677abc15c
|
@ -473,7 +473,7 @@ public class MainWindowController {
|
||||||
while ((line = input.readLine()) != null) {
|
while ((line = input.readLine()) != null) {
|
||||||
output = line;
|
output = line;
|
||||||
}
|
}
|
||||||
LOGGER.info(output);
|
LOGGER.info("which vlc: " + output);
|
||||||
input.close();
|
input.close();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
@ -604,8 +604,6 @@ public class MainWindowController {
|
||||||
* add data from films-list to films-table
|
* add data from films-list to films-table
|
||||||
*/
|
*/
|
||||||
public void addFilmsToTable(ObservableList<FilmTabelDataType> elementsList) {
|
public void addFilmsToTable(ObservableList<FilmTabelDataType> elementsList) {
|
||||||
|
|
||||||
System.out.println(elementsList.size());
|
|
||||||
|
|
||||||
for (FilmTabelDataType element : elementsList) {
|
for (FilmTabelDataType element : elementsList) {
|
||||||
|
|
||||||
|
|
|
@ -52,24 +52,18 @@ import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
|
||||||
|
|
||||||
public class PlayerController {
|
public class PlayerController {
|
||||||
|
|
||||||
@FXML
|
@FXML private MediaView mediaView;
|
||||||
private MediaView mediaView;
|
|
||||||
|
|
||||||
@FXML
|
@FXML private VBox bottomVBox;
|
||||||
private VBox bottomVBox;
|
|
||||||
|
|
||||||
@FXML
|
@FXML private HBox controlsHBox;
|
||||||
private HBox controlsHBox;
|
|
||||||
|
|
||||||
@FXML
|
@FXML private JFXSlider timeSlider;
|
||||||
private JFXSlider timeSlider;
|
|
||||||
|
|
||||||
@FXML
|
@FXML private JFXButton stopBtn;
|
||||||
private JFXButton stopBtn;
|
@FXML private JFXButton playBtn;
|
||||||
@FXML
|
@FXML private JFXButton fullscreenBtn;
|
||||||
private JFXButton playBtn;
|
@FXML private JFXButton nextEpBtn;
|
||||||
@FXML
|
|
||||||
private JFXButton fullscreenBtn;
|
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
private MainWindowController mainWCon;
|
private MainWindowController mainWCon;
|
||||||
|
@ -81,6 +75,9 @@ public class PlayerController {
|
||||||
private double seekTime = 0;
|
private double seekTime = 0;
|
||||||
private double startTime = 0;
|
private double startTime = 0;
|
||||||
private double duration = 0;
|
private double duration = 0;
|
||||||
|
private int season = 0;
|
||||||
|
private int episode = 0;
|
||||||
|
private int countdown = 0;
|
||||||
private boolean mousePressed = false;
|
private boolean mousePressed = false;
|
||||||
private boolean showControls = true;
|
private boolean showControls = true;
|
||||||
private boolean autoplay;
|
private boolean autoplay;
|
||||||
|
@ -123,6 +120,10 @@ public class PlayerController {
|
||||||
width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
|
width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
|
||||||
height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
|
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
|
// start the media if the player is ready
|
||||||
mediaPlayer.setOnReady(new Runnable() {
|
mediaPlayer.setOnReady(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -141,27 +142,40 @@ public class PlayerController {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {
|
public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {
|
||||||
currentTime = newValue.toMillis(); // set the current time
|
currentTime = newValue.toMillis(); // set the current time
|
||||||
int episode = !film.getEpisode().isEmpty() ? Integer.parseInt(film.getEpisode()) : 0;
|
double timeToEnd = (duration - currentTime);
|
||||||
int season = !film.getSeason().isEmpty() ? Integer.parseInt(film.getSeason()) : 0;
|
|
||||||
|
if (timeToEnd < 20000 && episode != 0 && autoplay) {
|
||||||
// if we are end time -10 seconds, do autoplay, if activated
|
// show 20 seconds before the end a button (next episode in 10 seconds)
|
||||||
if ((duration - currentTime) < 10000 && episode != 0 && autoplay) {
|
if(!nextEpBtn.isVisible())
|
||||||
autoplay = false;
|
nextEpBtn.setVisible(true);
|
||||||
mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time
|
|
||||||
FilmTabelDataType nextFilm = mainWCon.getDbController().getNextEpisode(film.getTitle(), episode, season);
|
if(countdown != (int)((timeToEnd -10000) / 1000)) {
|
||||||
if (nextFilm != null) {
|
countdown = (int)((timeToEnd -10000) / 1000);
|
||||||
mediaPlayer.stop();
|
nextEpBtn.setText("next episode in " + countdown + " seconds"); // TODO translate
|
||||||
init(mainWCon, player, nextFilm);
|
bottomVBox.setVisible(true);
|
||||||
autoplay = true;
|
}
|
||||||
|
|
||||||
|
// if we are end time -10 seconds, do autoplay, if activated
|
||||||
|
if(timeToEnd < 10000){
|
||||||
|
nextEpBtn.setVisible(false);
|
||||||
|
autoPlayNewFilm();
|
||||||
}
|
}
|
||||||
} else if ((duration - currentTime) < 120) {
|
} else if (timeToEnd < 120) {
|
||||||
// if we are -20ms stop the media
|
// if we are 120ms to the end stop the media
|
||||||
mediaPlayer.stop();
|
mediaPlayer.stop();
|
||||||
mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time
|
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) {
|
if (!mousePressed) {
|
||||||
timeSlider.setValue((currentTime / 1000) / 60);
|
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
|
// hide controls timer initialization
|
||||||
final Timer timer = new Timer();
|
final Timer timer = new Timer();
|
||||||
TimerTask controlAnimationTask = null; // task to execute save operation
|
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
|
@Override
|
||||||
public void handle(MouseEvent mouseEvent) {
|
public void handle(MouseEvent mouseEvent) {
|
||||||
|
@ -254,7 +268,6 @@ public class PlayerController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void playBtnAction(ActionEvent event) {
|
void playBtnAction(ActionEvent event) {
|
||||||
|
|
||||||
if (mediaPlayer.getStatus().equals(Status.PLAYING)) {
|
if (mediaPlayer.getStatus().equals(Status.PLAYING)) {
|
||||||
mediaPlayer.pause();
|
mediaPlayer.pause();
|
||||||
playBtn.setGraphic(play_arrow_black);
|
playBtn.setGraphic(play_arrow_black);
|
||||||
|
@ -263,6 +276,22 @@ public class PlayerController {
|
||||||
playBtn.setGraphic(pause_black);
|
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() {
|
public MediaPlayer getMediaPlayer() {
|
||||||
return mediaPlayer;
|
return mediaPlayer;
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
<?import javafx.scene.layout.HBox?>
|
<?import javafx.scene.layout.HBox?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.media.MediaView?>
|
<?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>
|
<children>
|
||||||
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<children>
|
<children>
|
||||||
|
@ -34,5 +35,15 @@
|
||||||
</HBox>
|
</HBox>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</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>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
Loading…
Reference in New Issue