diff --git a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java index f6d918b..93e75ad 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java +++ b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java @@ -104,6 +104,9 @@ public class MainWindowController { @FXML private AnchorPane mainAnchorPane; + @FXML + private AnchorPane tableModeAnchorPane; + @FXML private ScrollPane settingsScrollPane; @@ -147,7 +150,7 @@ public class MainWindowController { private JFXButton debugBtn; @FXML - public JFXButton updateBtn; + private JFXButton updateBtn; @FXML private JFXButton addDirectoryBtn; @@ -161,6 +164,9 @@ public class MainWindowController { @FXML private JFXToggleButton autoUpdateToggleBtn; + @FXML + private JFXToggleButton autoplayToggleBtn; + @FXML private JFXTextField searchTextField; @@ -228,6 +234,7 @@ public class MainWindowController { private boolean settingsTrue = false; private boolean autoUpdate = false; private boolean useBeta = false; + private boolean autoplay = false; private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); private int hashA = -647380320; @@ -513,6 +520,7 @@ public class MainWindowController { updateBtn.setFont(Font.font("System", 12)); autoUpdateToggleBtn.setSelected(isAutoUpdate()); + autoplayToggleBtn.setSelected(isAutoplay()); languageChoisBox.setItems(languages); branchChoisBox.setItems(branches); @@ -529,7 +537,7 @@ public class MainWindowController { @FXML private void playbtnclicked() { if (isSupportedFormat(currentTableFilm)) { - new Player(currentTableFilm, dbController); + new Player(mainWindowController); } else { LOGGER.error("using fallback player!"); @@ -669,7 +677,7 @@ public class MainWindowController { @FXML private void autoUpdateToggleBtnAction(){ - if (autoUpdate) { + if (isAutoUpdate()) { setAutoUpdate(false); } else { setAutoUpdate(true); @@ -677,14 +685,18 @@ public class MainWindowController { saveSettings(); } + @FXML + private void autoplayToggleBtnAction(){ + if (isAutoplay()) { + setAutoplay(false); + } else { + setAutoplay(true); + } + saveSettings(); + } + // refresh the selected child of the root node private void refreshTable() { - System.out.println("refresh"); - System.out.println(filmRoot.getChildren().get(indexTable).getValue()); - System.out.println(currentTableFilm); - -// filmRoot.getChildren().get() - filmRoot.getChildren().get(indexTable).setValue(filmsList.get(indexList)); } @@ -755,7 +767,6 @@ public class MainWindowController { } } - //set color of UI-Elements /** * set the color of the GUI-Elements * if usedColor is less than checkColor set text fill white, else black @@ -853,6 +864,7 @@ public class MainWindowController { fontsizeLbl.setText(getBundle().getString("fontsizeLbl")); languageLbl.setText(getBundle().getString("languageLbl")); autoUpdateToggleBtn.setText(getBundle().getString("autoUpdate")); + autoplayToggleBtn.setText(getBundle().getString("autoplay")); branchLbl.setText(getBundle().getString("branchLbl")); columnStreamUrl.setText(getBundle().getString("columnStreamUrl")); columnTitle.setText(getBundle().getString("columnName")); @@ -908,6 +920,7 @@ public class MainWindowController { props.setProperty("color", getColor()); props.setProperty("autoUpdate", String.valueOf(isAutoUpdate())); props.setProperty("useBeta", String.valueOf(isUseBeta())); + props.setProperty("autoplay", String.valueOf(isAutoplay())); props.setProperty("size", getSize().toString()); props.setProperty("local", getLocal()); props.setProperty("ratingSortType", columnFavorite.getSortType().toString()); @@ -958,6 +971,13 @@ public class MainWindowController { LOGGER.error("cloud not load autoUpdate", e); setUseBeta(false); } + + try { + setAutoplay(Boolean.parseBoolean(props.getProperty("autoplay"))); + } catch (Exception e) { + LOGGER.error("cloud not load autoplay", e); + setAutoplay(false); + } try { setLocal(props.getProperty("local")); @@ -1032,6 +1052,10 @@ public class MainWindowController { public String getColor() { return color; } + + public FilmTabelDataType getCurrentTableFilm() { + return currentTableFilm; + } public String getCurrentTitle() { return currentTableFilm.getTitle(); @@ -1072,6 +1096,14 @@ public class MainWindowController { public void setUseBeta(boolean useBeta) { this.useBeta = useBeta; } + + public boolean isAutoplay() { + return autoplay; + } + + public void setAutoplay(boolean autoplay) { + this.autoplay = autoplay; + } public void setLocal(String input) { this.local = input; diff --git a/src/main/java/kellerkinder/HomeFlix/player/Player.java b/src/main/java/kellerkinder/HomeFlix/player/Player.java index 5bbc3c2..33e6c5d 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/Player.java +++ b/src/main/java/kellerkinder/HomeFlix/player/Player.java @@ -30,24 +30,23 @@ import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; import javafx.stage.WindowEvent; import kellerkinder.HomeFlix.application.Main; -import kellerkinder.HomeFlix.controller.DBController; +import kellerkinder.HomeFlix.application.MainWindowController; import kellerkinder.HomeFlix.datatypes.FilmTabelDataType; public class Player { + private MainWindowController mainWindowController; private PlayerController playerController; - private DBController dbController; private Stage stage; private AnchorPane pane; private Scene scene; /** * generate a new PlayerWindow - * @param entry the film object - * @param dbController the dbController object + * @param mainWindowController the MainWindowController */ - public Player(FilmTabelDataType film, DBController dbController) { - this.dbController = dbController; + public Player(MainWindowController mainWindowController) { + this.mainWindowController = mainWindowController; try { FXMLLoader fxmlLoader = new FXMLLoader(ClassLoader.getSystemResource("fxml/PlayerWindow.fxml")); pane = (AnchorPane) fxmlLoader.load(); @@ -58,14 +57,15 @@ public class Player { stage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); stage.setOnCloseRequest(new EventHandler() { public void handle(WindowEvent we) { - dbController.setCurrentTime(film.getStreamUrl(), playerController.getCurrentTime()); + mainWindowController.getDbController().setCurrentTime(mainWindowController.getCurrentStreamUrl(), + playerController.getCurrentTime()); playerController.getMediaPlayer().stop(); stage.close(); } }); playerController = fxmlLoader.getController(); - playerController.init(film, this, dbController); + playerController.init(mainWindowController, this, mainWindowController.getCurrentTableFilm()); stage.setFullScreen(true); stage.show(); @@ -75,7 +75,7 @@ public class Player { } public void playNewFilm(FilmTabelDataType film) { - playerController.init(film, this, dbController); + playerController.init(mainWindowController, this, film); } public Stage getStage() { diff --git a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java index fdad932..7156aca 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java +++ b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java @@ -46,14 +46,14 @@ import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaPlayer.Status; import javafx.scene.media.MediaView; import javafx.util.Duration; -import kellerkinder.HomeFlix.controller.DBController; +import kellerkinder.HomeFlix.application.MainWindowController; import kellerkinder.HomeFlix.datatypes.FilmTabelDataType; public class PlayerController { @FXML private MediaView mediaView; - + @FXML private VBox bottomVBox; @@ -62,10 +62,10 @@ public class PlayerController { @FXML private JFXSlider timeSlider; - + @FXML private JFXButton stopBtn; - + @FXML private JFXButton playBtn; @@ -73,10 +73,10 @@ public class PlayerController { private JFXButton fullscreenBtn; private Player player; - private DBController dbController; + private MainWindowController mainWCon; private Media media; private MediaPlayer mediaPlayer; - + private FilmTabelDataType film; private double currentTime = 0; private double seekTime = 0; @@ -84,8 +84,8 @@ public class PlayerController { private double duration = 0; private boolean mousePressed = false; private boolean showControls = true; - private boolean autoplay = true; - + private boolean autoplay; + private ImageView stop_black = new ImageView(new Image("icons/ic_stop_black_24dp_1x.png")); private ImageView play_arrow_black = new ImageView(new Image("icons/ic_play_arrow_black_24dp_1x.png")); private ImageView pause_black = new ImageView(new Image("icons/ic_pause_black_24dp_1x.png")); @@ -94,23 +94,26 @@ public class PlayerController { /** * initialize the new PlayerWindow - * @param entry the film object + * @param entry the film object * @param player the player object (needed for closing action) * @param dbController the dbController object */ - public void init(FilmTabelDataType film, Player player, DBController dbController) { - this.film = film; + public void init(MainWindowController mainWCon, Player player, FilmTabelDataType film) { + this.mainWCon = mainWCon; this.player = player; - this.dbController = dbController; + this.film = film; + startTime = mainWCon.getDbController().getCurrentTime(film.getStreamUrl()); + autoplay = mainWCon.isAutoplay(); initActions(); - + if (film.getStreamUrl().startsWith("http")) { media = new Media(film.getStreamUrl()); } else { media = new Media(new File(film.getStreamUrl()).toURI().toString()); } - startTime = dbController.getCurrentTime(film.getStreamUrl()); - + startTime = mainWCon.getDbController().getCurrentTime(film.getStreamUrl()); + autoplay = mainWCon.isAutoplay(); + mediaPlayer = new MediaPlayer(media); mediaView.setPreserveRatio(true); mediaView.setMediaPlayer(mediaPlayer); @@ -121,56 +124,59 @@ public class PlayerController { width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height")); + // start the media if the player is ready mediaPlayer.setOnReady(new Runnable() { - @Override - public void run() { - duration = media.getDuration().toMillis(); - - timeSlider.setMax((duration/1000)/60); + @Override + public void run() { + duration = media.getDuration().toMillis(); - mediaPlayer.play(); - mediaPlayer.seek(Duration.millis(startTime)); - } - }); - + timeSlider.setMax((duration / 1000) / 60); + + mediaPlayer.play(); + mediaPlayer.seek(Duration.millis(startTime)); + } + }); + + // every time the play time changes execute this + // TODO rework autoplay mediaPlayer.currentTimeProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, Duration oldValue, Duration newValue) { - currentTime = newValue.toMillis(); - int episode = !film.getEpisode().isEmpty() ? Integer.parseInt(film.getEpisode()) : 0; - - if ((duration - currentTime) < 10000 && episode != 0 && autoplay) { - autoplay = false; - dbController.setCurrentTime(film.getStreamUrl(), 0); // reset old video start time - - //start the new film - FilmTabelDataType nextFilm = dbController.getNextEpisode(film.getTitle(), episode + 1); - if (nextFilm != null) { - mediaPlayer.stop(); - player.playNewFilm(nextFilm); - autoplay = true; + @Override + public void changed(ObservableValue observable, Duration oldValue, Duration newValue) { + currentTime = newValue.toMillis(); // set the current time + int episode = !film.getEpisode().isEmpty() ? Integer.parseInt(film.getEpisode()) : 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 + 1)); + if (nextFilm != null) { + mediaPlayer.stop(); + player.playNewFilm(nextFilm); + autoplay = true; } } else if ((duration - currentTime) < 100) { mediaPlayer.stop(); } - if (!mousePressed) { - timeSlider.setValue((currentTime/1000)/60); + if (!mousePressed) { + timeSlider.setValue((currentTime / 1000) / 60); } - } + } }); - + + // set the control elements to the correct value stopBtn.setGraphic(stop_black); playBtn.setGraphic(pause_black); fullscreenBtn.setGraphic(fullscreen_exit_black); timeSlider.setValue(0); } - + /** * initialize some PlayerWindow GUI-Elements actions */ private void initActions() { - + player.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, new EventHandler() { // hide controls timer init final Timer timer = new Timer(); @@ -179,13 +185,13 @@ public class PlayerController { @Override public void handle(MouseEvent mouseEvent) { - + // show controls if (!showControls) { player.getScene().setCursor(Cursor.DEFAULT); bottomVBox.setVisible(true); } - + // hide controls if (controlAnimationTask != null) controlAnimationTask.cancel(); @@ -202,40 +208,40 @@ public class PlayerController { } }); + // if the mouse on the timeSlider is released seek to the new position timeSlider.setOnMouseReleased(new EventHandler() { - @Override - public void handle(MouseEvent event) { - mediaPlayer.seek(new Duration(seekTime)); - mousePressed = false; - } + @Override + public void handle(MouseEvent event) { + mediaPlayer.seek(new Duration(seekTime)); + mousePressed = false; + } }); - + timeSlider.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent event) { mousePressed = true; - } + } }); - + + // get the new seek time timeSlider.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Number old_val, Number new_val) { - seekTime = (double) new_val*1000*60; + seekTime = (double) new_val * 1000 * 60; } }); } - + @FXML void stopBtnAction(ActionEvent event) { - - dbController.setCurrentTime(film.getStreamUrl(), currentTime); - + mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), currentTime); mediaPlayer.stop(); player.getStage().close(); } @FXML - void fullscreenBtnAction(ActionEvent event) { + void fullscreenBtnAction(ActionEvent event) { if (player.getStage().isFullScreen()) { player.getStage().setFullScreen(false); fullscreenBtn.setGraphic(fullscreen_black); diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml index cec24f0..43f47e8 100644 --- a/src/main/resources/fxml/MainWindow.fxml +++ b/src/main/resources/fxml/MainWindow.fxml @@ -24,58 +24,38 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + @@ -139,10 +119,26 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/locals/HomeFlix-Local_de_DE.properties b/src/main/resources/locals/HomeFlix-Local_de_DE.properties index f8c6279..d821e66 100644 --- a/src/main/resources/locals/HomeFlix-Local_de_DE.properties +++ b/src/main/resources/locals/HomeFlix-Local_de_DE.properties @@ -20,6 +20,7 @@ updateBtnChecking = Es wird nach Updates gesucht... updateBtnUpdateAvailable = Update verf\u00FCgbar updateBtnNoUpdateAvailable = Kein Update verf\u00FCgbar autoUpdate = beim Start nach Updates suchen: +autoplay = autoplay branchLbl = Updatezweig #column translations diff --git a/src/main/resources/locals/HomeFlix-Local_en_US.properties b/src/main/resources/locals/HomeFlix-Local_en_US.properties index 9df7ff2..6082c9d 100644 --- a/src/main/resources/locals/HomeFlix-Local_en_US.properties +++ b/src/main/resources/locals/HomeFlix-Local_en_US.properties @@ -20,6 +20,7 @@ updateBtnChecking = checking for updates... updateBtnUpdateAvailable = update available updateBtnNoUpdateAvailable = no update available autoUpdate = check at startup for updates: +autoplay = autoplay branchLbl = Branch #column translations