Project-HomeFlix/src/main/java/kellerkinder/HomeFlix/player/Player.java

97 lines
2.8 KiB
Java

/**
* Project-HomeFlix
*
* Copyright 2016-2019 <@Seil0>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
package kellerkinder.HomeFlix.player;
import java.net.URLConnection;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import kellerkinder.HomeFlix.application.Main;
import kellerkinder.HomeFlix.controller.DBController;
public class Player {
private PlayerController playerController;
private Stage stage;
private AnchorPane pane;
private Scene scene;
// TODO move the players choose logic to a separate static class
/**
* generate a new PlayerWindow
* @param currentTableFilm the currently selected film
*/
public Player(String streamURL) {
playerController = new PlayerController(this, streamURL);
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);
stage.setScene(scene);
stage.setTitle("HomeFlix");
stage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png")));
stage.setOnCloseRequest(event -> {
DBController.getInstance().setCurrentTime(streamURL, playerController.getCurrentTime());
playerController.getMediaPlayer().stop();
stage.close();
});
playerController.init();
stage.setFullScreen(true);
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public Stage getStage() {
return stage;
}
public Scene getScene() {
return scene;
}
/**
* check if a film is supported by the HomeFlixPlayer or not this is the case if
* the mime type is mp4
*
* @param entry the film you want to check
* @return true if so, false if not
*/
public static boolean isSupportedFormat(String streamURL) {
String mimeType = URLConnection.guessContentTypeFromName(streamURL);
return mimeType != null && (mimeType.contains("mp4") || mimeType.contains("vp6"));
}
}