clean up
This commit is contained in:
parent
a677abc15c
commit
1d06aaeaa2
|
@ -34,6 +34,8 @@ import java.math.BigInteger;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -214,7 +216,7 @@ public class MainWindowController {
|
||||||
initActions();
|
initActions();
|
||||||
dbController.init();
|
dbController.init();
|
||||||
|
|
||||||
// posterModeStartup(); // TODO testing
|
// posterModeStartup(); // TODO testing DO NOT USE THIS!!
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize general UI elements
|
// Initialize general UI elements
|
||||||
|
@ -441,7 +443,7 @@ public class MainWindowController {
|
||||||
LOGGER.info("loading from cache: " + getCurrentTitle());
|
LOGGER.info("loading from cache: " + getCurrentTitle());
|
||||||
dbController.readCache(getCurrentStreamUrl());
|
dbController.readCache(getCurrentStreamUrl());
|
||||||
} else {
|
} else {
|
||||||
Thread omdbAPIThread = new Thread(new OMDbAPIController(main, dbController, currentTableFilm, omdbAPIKey));
|
Thread omdbAPIThread = new Thread(new OMDbAPIController(main, dbController, currentTableFilm, omdbAPIKey, true));
|
||||||
omdbAPIThread.setName("OMDbAPI");
|
omdbAPIThread.setName("OMDbAPI");
|
||||||
omdbAPIThread.start();
|
omdbAPIThread.start();
|
||||||
}
|
}
|
||||||
|
@ -817,18 +819,21 @@ public class MainWindowController {
|
||||||
*/
|
*/
|
||||||
private void checkAllPosters() {
|
private void checkAllPosters() {
|
||||||
// get all not cached entries, none of them should have a cached poster
|
// get all not cached entries, none of them should have a cached poster
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(5);
|
||||||
|
|
||||||
for (FilmTabelDataType entry : dbController.getAllNotCachedEntries()) {
|
for (FilmTabelDataType entry : dbController.getAllNotCachedEntries()) {
|
||||||
System.out.println(entry.getStreamUrl() + " is NOT cached!");
|
System.out.println(entry.getStreamUrl() + " is NOT cached!");
|
||||||
// TODO get all needed posters eg cache all not cached entries
|
|
||||||
// TODO for entries not available show homeflix logo
|
Runnable OMDbAPIWorker = new OMDbAPIController(main, dbController, entry, omdbAPIKey, false);
|
||||||
|
executor.execute(OMDbAPIWorker);
|
||||||
|
|
||||||
|
// TODO for entries not available show homeflix logo and set cached
|
||||||
}
|
}
|
||||||
|
executor.shutdown();
|
||||||
|
|
||||||
// Thread omdbAPIThread = new Thread(new OMDbAPIController(main, dbController, currentTableFilm, omdbAPIKey));
|
// TODO show loading screen
|
||||||
// omdbAPIThread.setName("OMDbAPI");
|
|
||||||
// omdbAPIThread.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// getter and setter
|
// getter and setter
|
||||||
public DBController getDbController() {
|
public DBController getDbController() {
|
||||||
return dbController;
|
return dbController;
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class OMDbAPIController implements Runnable {
|
||||||
private String omdbAPIKey;
|
private String omdbAPIKey;
|
||||||
private String URL = "https://www.omdbapi.com/?apikey=";
|
private String URL = "https://www.omdbapi.com/?apikey=";
|
||||||
private boolean useEpisode = true;
|
private boolean useEpisode = true;
|
||||||
|
private boolean refresh;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,11 +60,12 @@ public class OMDbAPIController implements Runnable {
|
||||||
* @param currentTableFilm the current film object
|
* @param currentTableFilm the current film object
|
||||||
* @param omdbAPIKey the omdbAPI key
|
* @param omdbAPIKey the omdbAPI key
|
||||||
*/
|
*/
|
||||||
public OMDbAPIController(Main main, DBController dbController, FilmTabelDataType currentTableFilm, String omdbAPIKey) {
|
public OMDbAPIController(Main main, DBController dbController, FilmTabelDataType currentTableFilm, String omdbAPIKey, boolean refresh) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
this.dbController = dbController;
|
this.dbController = dbController;
|
||||||
this.currentTableFilm = currentTableFilm;
|
this.currentTableFilm = currentTableFilm;
|
||||||
this.omdbAPIKey = omdbAPIKey;
|
this.omdbAPIKey = omdbAPIKey;
|
||||||
|
this.refresh = refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,10 +132,12 @@ public class OMDbAPIController implements Runnable {
|
||||||
dbController.setCached(currentTableFilm.getStreamUrl());
|
dbController.setCached(currentTableFilm.getStreamUrl());
|
||||||
|
|
||||||
// load data to the MainWindowController
|
// load data to the MainWindowController
|
||||||
Platform.runLater(() -> {
|
if (refresh) {
|
||||||
dbController.readCache(currentTableFilm.getStreamUrl());
|
Platform.runLater(() -> {
|
||||||
});
|
dbController.readCache(currentTableFilm.getStreamUrl());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,12 @@ public class Player {
|
||||||
* @param mainWindowController the MainWindowController
|
* @param mainWindowController the MainWindowController
|
||||||
*/
|
*/
|
||||||
public Player(MainWindowController mainWindowController) {
|
public Player(MainWindowController mainWindowController) {
|
||||||
|
playerController = new PlayerController(mainWindowController, this, mainWindowController.getCurrentTableFilm());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader();
|
FXMLLoader fxmlLoader = new FXMLLoader();
|
||||||
fxmlLoader.setLocation(getClass().getResource("/fxml/PlayerWindow.fxml"));
|
fxmlLoader.setLocation(getClass().getResource("/fxml/PlayerWindow.fxml"));
|
||||||
|
fxmlLoader.setController(playerController);
|
||||||
pane = (AnchorPane) fxmlLoader.load();
|
pane = (AnchorPane) fxmlLoader.load();
|
||||||
stage = new Stage();
|
stage = new Stage();
|
||||||
scene = new Scene(pane);
|
scene = new Scene(pane);
|
||||||
|
@ -62,8 +65,7 @@ public class Player {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
playerController = fxmlLoader.getController();
|
playerController.init();
|
||||||
playerController.init(mainWindowController, this, mainWindowController.getCurrentTableFilm());
|
|
||||||
|
|
||||||
stage.setFullScreen(true);
|
stage.setFullScreen(true);
|
||||||
stage.show();
|
stage.show();
|
||||||
|
|
|
@ -87,19 +87,23 @@ public class PlayerController {
|
||||||
private ImageView pause_black = new ImageView(new Image("icons/ic_pause_black_24dp_1x.png"));
|
private ImageView pause_black = new ImageView(new Image("icons/ic_pause_black_24dp_1x.png"));
|
||||||
private ImageView fullscreen_black = new ImageView(new Image("icons/ic_fullscreen_black_24dp_1x.png"));
|
private ImageView fullscreen_black = new ImageView(new Image("icons/ic_fullscreen_black_24dp_1x.png"));
|
||||||
private ImageView fullscreen_exit_black = new ImageView(new Image("icons/ic_fullscreen_exit_black_24dp_1x.png"));
|
private ImageView fullscreen_exit_black = new ImageView(new Image("icons/ic_fullscreen_exit_black_24dp_1x.png"));
|
||||||
|
|
||||||
/** FIXME double set currentTime()
|
/**
|
||||||
* initialize the new PlayerWindow
|
* create a new PlayerWindow object
|
||||||
* @param entry the film object
|
* @param mainWCon the MainWindowController TODO do we need this?
|
||||||
* @param player the player object (needed for closing action)
|
* @param player the player object (needed for closing action)
|
||||||
* @param dbController the dbController object
|
* @param film the film object
|
||||||
*/
|
*/
|
||||||
public void init(MainWindowController mainWCon, Player player, FilmTabelDataType film) {
|
public PlayerController(MainWindowController mainWCon, Player player, FilmTabelDataType film) {
|
||||||
this.mainWCon = mainWCon;
|
this.mainWCon = mainWCon;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.film = film;
|
this.film = film;
|
||||||
startTime = mainWCon.getDbController().getCurrentTime(film.getStreamUrl());
|
}
|
||||||
autoplay = mainWCon.isAutoplay();
|
|
||||||
|
/**
|
||||||
|
* initialize the PlayerWindow
|
||||||
|
*/
|
||||||
|
public void init() {
|
||||||
initActions();
|
initActions();
|
||||||
|
|
||||||
if (film.getStreamUrl().startsWith("http")) {
|
if (film.getStreamUrl().startsWith("http")) {
|
||||||
|
@ -107,9 +111,8 @@ public class PlayerController {
|
||||||
} else {
|
} else {
|
||||||
media = new Media(new File(film.getStreamUrl()).toURI().toString());
|
media = new Media(new File(film.getStreamUrl()).toURI().toString());
|
||||||
}
|
}
|
||||||
startTime = mainWCon.getDbController().getCurrentTime(film.getStreamUrl());
|
|
||||||
autoplay = mainWCon.isAutoplay();
|
|
||||||
|
|
||||||
|
// create the MediaPlayer object
|
||||||
mediaPlayer = new MediaPlayer(media);
|
mediaPlayer = new MediaPlayer(media);
|
||||||
mediaView.setPreserveRatio(true);
|
mediaView.setPreserveRatio(true);
|
||||||
mediaView.setMediaPlayer(mediaPlayer);
|
mediaView.setMediaPlayer(mediaPlayer);
|
||||||
|
@ -120,16 +123,26 @@ 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"));
|
||||||
|
|
||||||
|
startTime = mainWCon.getDbController().getCurrentTime(film.getStreamUrl());
|
||||||
|
autoplay = mainWCon.isAutoplay();
|
||||||
season = !film.getSeason().isEmpty() ? Integer.parseInt(film.getSeason()) : 0;
|
season = !film.getSeason().isEmpty() ? Integer.parseInt(film.getSeason()) : 0;
|
||||||
episode = !film.getEpisode().isEmpty() ? Integer.parseInt(film.getEpisode()) : 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;");
|
|
||||||
|
|
||||||
|
initMediaPlayer();
|
||||||
|
|
||||||
|
// set the control elements to the correct value
|
||||||
|
stopBtn.setGraphic(stop_black);
|
||||||
|
playBtn.setGraphic(pause_black);
|
||||||
|
fullscreenBtn.setGraphic(fullscreen_exit_black);
|
||||||
|
timeSlider.setValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMediaPlayer() {
|
||||||
// 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
|
||||||
public void run() {
|
public void run() {
|
||||||
duration = media.getDuration().toMillis();
|
duration = media.getDuration().toMillis();
|
||||||
|
|
||||||
timeSlider.setMax((duration / 1000) / 60);
|
timeSlider.setMax((duration / 1000) / 60);
|
||||||
|
|
||||||
mediaPlayer.play();
|
mediaPlayer.play();
|
||||||
|
@ -146,17 +159,17 @@ public class PlayerController {
|
||||||
|
|
||||||
if (timeToEnd < 20000 && episode != 0 && autoplay) {
|
if (timeToEnd < 20000 && episode != 0 && autoplay) {
|
||||||
// show 20 seconds before the end a button (next episode in 10 seconds)
|
// show 20 seconds before the end a button (next episode in 10 seconds)
|
||||||
if(!nextEpBtn.isVisible())
|
if (!nextEpBtn.isVisible())
|
||||||
nextEpBtn.setVisible(true);
|
nextEpBtn.setVisible(true);
|
||||||
|
|
||||||
if(countdown != (int)((timeToEnd -10000) / 1000)) {
|
if (countdown != (int) ((timeToEnd - 10000) / 1000)) {
|
||||||
countdown = (int)((timeToEnd -10000) / 1000);
|
countdown = (int) ((timeToEnd - 10000) / 1000);
|
||||||
nextEpBtn.setText("next episode in " + countdown + " seconds"); // TODO translate
|
nextEpBtn.setText("next episode in " + countdown + " seconds"); // TODO translate
|
||||||
bottomVBox.setVisible(true);
|
bottomVBox.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we are end time -10 seconds, do autoplay, if activated
|
// if we are end time -10 seconds, do autoplay, if activated
|
||||||
if(timeToEnd < 10000){
|
if (timeToEnd < 10000) {
|
||||||
nextEpBtn.setVisible(false);
|
nextEpBtn.setVisible(false);
|
||||||
autoPlayNewFilm();
|
autoPlayNewFilm();
|
||||||
}
|
}
|
||||||
|
@ -166,25 +179,16 @@ public class PlayerController {
|
||||||
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);
|
playBtn.setGraphic(play_arrow_black);
|
||||||
} else {
|
} else {
|
||||||
if(nextEpBtn.isVisible())
|
if (nextEpBtn.isVisible())
|
||||||
nextEpBtn.setVisible(false);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// set the control elements to the correct value
|
|
||||||
stopBtn.setGraphic(stop_black);
|
|
||||||
playBtn.setGraphic(pause_black);
|
|
||||||
fullscreenBtn.setGraphic(fullscreen_exit_black);
|
|
||||||
timeSlider.setValue(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -288,7 +292,8 @@ public class PlayerController {
|
||||||
FilmTabelDataType nextFilm = mainWCon.getDbController().getNextEpisode(film.getTitle(), episode, season);
|
FilmTabelDataType nextFilm = mainWCon.getDbController().getNextEpisode(film.getTitle(), episode, season);
|
||||||
if (nextFilm != null) {
|
if (nextFilm != null) {
|
||||||
mediaPlayer.stop();
|
mediaPlayer.stop();
|
||||||
init(mainWCon, player, nextFilm);
|
film = nextFilm;
|
||||||
|
init();
|
||||||
autoplay = true;
|
autoplay = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<?import javafx.scene.media.MediaView?>
|
<?import javafx.scene.media.MediaView?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<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">
|
<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">
|
||||||
<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>
|
||||||
|
|
Loading…
Reference in New Issue