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