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.util.Locale;
|
||||
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.Logger;
|
||||
|
@ -214,7 +216,7 @@ public class MainWindowController {
|
|||
initActions();
|
||||
dbController.init();
|
||||
|
||||
// posterModeStartup(); // TODO testing
|
||||
// posterModeStartup(); // TODO testing DO NOT USE THIS!!
|
||||
}
|
||||
|
||||
// Initialize general UI elements
|
||||
|
@ -441,7 +443,7 @@ public class MainWindowController {
|
|||
LOGGER.info("loading from cache: " + getCurrentTitle());
|
||||
dbController.readCache(getCurrentStreamUrl());
|
||||
} 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.start();
|
||||
}
|
||||
|
@ -817,18 +819,21 @@ public class MainWindowController {
|
|||
*/
|
||||
private void checkAllPosters() {
|
||||
// get all not cached entries, none of them should have a cached poster
|
||||
ExecutorService executor = Executors.newFixedThreadPool(5);
|
||||
|
||||
for (FilmTabelDataType entry : dbController.getAllNotCachedEntries()) {
|
||||
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));
|
||||
// omdbAPIThread.setName("OMDbAPI");
|
||||
// omdbAPIThread.start();
|
||||
// TODO show loading screen
|
||||
}
|
||||
|
||||
|
||||
// getter and setter
|
||||
public DBController getDbController() {
|
||||
return dbController;
|
||||
|
|
|
@ -50,6 +50,7 @@ public class OMDbAPIController implements Runnable {
|
|||
private String omdbAPIKey;
|
||||
private String URL = "https://www.omdbapi.com/?apikey=";
|
||||
private boolean useEpisode = true;
|
||||
private boolean refresh;
|
||||
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 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.dbController = dbController;
|
||||
this.currentTableFilm = currentTableFilm;
|
||||
this.omdbAPIKey = omdbAPIKey;
|
||||
this.refresh = refresh;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,10 +132,12 @@ public class OMDbAPIController implements Runnable {
|
|||
dbController.setCached(currentTableFilm.getStreamUrl());
|
||||
|
||||
// load data to the MainWindowController
|
||||
Platform.runLater(() -> {
|
||||
dbController.readCache(currentTableFilm.getStreamUrl());
|
||||
});
|
||||
|
||||
if (refresh) {
|
||||
Platform.runLater(() -> {
|
||||
dbController.readCache(currentTableFilm.getStreamUrl());
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,12 @@ public class Player {
|
|||
* @param mainWindowController the MainWindowController
|
||||
*/
|
||||
public Player(MainWindowController mainWindowController) {
|
||||
playerController = new PlayerController(mainWindowController, this, mainWindowController.getCurrentTableFilm());
|
||||
|
||||
try {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader();
|
||||
fxmlLoader.setLocation(getClass().getResource("/fxml/PlayerWindow.fxml"));
|
||||
fxmlLoader.setController(playerController);
|
||||
pane = (AnchorPane) fxmlLoader.load();
|
||||
stage = new Stage();
|
||||
scene = new Scene(pane);
|
||||
|
@ -62,8 +65,7 @@ public class Player {
|
|||
}
|
||||
});
|
||||
|
||||
playerController = fxmlLoader.getController();
|
||||
playerController.init(mainWindowController, this, mainWindowController.getCurrentTableFilm());
|
||||
playerController.init();
|
||||
|
||||
stage.setFullScreen(true);
|
||||
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 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"));
|
||||
|
||||
/** FIXME double set currentTime()
|
||||
* initialize the new PlayerWindow
|
||||
* @param entry the film object
|
||||
* @param player the player object (needed for closing action)
|
||||
* @param dbController the dbController object
|
||||
|
||||
/**
|
||||
* create a new PlayerWindow object
|
||||
* @param mainWCon the MainWindowController TODO do we need this?
|
||||
* @param player the player object (needed for closing action)
|
||||
* @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.player = player;
|
||||
this.film = film;
|
||||
startTime = mainWCon.getDbController().getCurrentTime(film.getStreamUrl());
|
||||
autoplay = mainWCon.isAutoplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the PlayerWindow
|
||||
*/
|
||||
public void init() {
|
||||
initActions();
|
||||
|
||||
if (film.getStreamUrl().startsWith("http")) {
|
||||
|
@ -107,9 +111,8 @@ public class PlayerController {
|
|||
} else {
|
||||
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);
|
||||
mediaView.setPreserveRatio(true);
|
||||
mediaView.setMediaPlayer(mediaPlayer);
|
||||
|
@ -120,16 +123,26 @@ public class PlayerController {
|
|||
width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
|
||||
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;
|
||||
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
|
||||
mediaPlayer.setOnReady(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
duration = media.getDuration().toMillis();
|
||||
|
||||
timeSlider.setMax((duration / 1000) / 60);
|
||||
|
||||
mediaPlayer.play();
|
||||
|
@ -146,17 +159,17 @@ public class PlayerController {
|
|||
|
||||
if (timeToEnd < 20000 && episode != 0 && autoplay) {
|
||||
// show 20 seconds before the end a button (next episode in 10 seconds)
|
||||
if(!nextEpBtn.isVisible())
|
||||
if (!nextEpBtn.isVisible())
|
||||
nextEpBtn.setVisible(true);
|
||||
|
||||
if(countdown != (int)((timeToEnd -10000) / 1000)) {
|
||||
countdown = (int)((timeToEnd -10000) / 1000);
|
||||
|
||||
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){
|
||||
if (timeToEnd < 10000) {
|
||||
nextEpBtn.setVisible(false);
|
||||
autoPlayNewFilm();
|
||||
}
|
||||
|
@ -166,25 +179,16 @@ public class PlayerController {
|
|||
mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time
|
||||
playBtn.setGraphic(play_arrow_black);
|
||||
} else {
|
||||
if(nextEpBtn.isVisible())
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
if (nextFilm != null) {
|
||||
mediaPlayer.stop();
|
||||
init(mainWCon, player, nextFilm);
|
||||
film = nextFilm;
|
||||
init();
|
||||
autoplay = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<?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/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>
|
||||
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
|
|
Loading…
Reference in New Issue