added first version of the new player
* added a javafx mediaplayer based player
This commit is contained in:
parent
2d0d138c08
commit
2881c1f9d6
|
@ -97,6 +97,7 @@ import kellerkinder.HomeFlix.controller.DBController;
|
||||||
import kellerkinder.HomeFlix.controller.OMDbAPIController;
|
import kellerkinder.HomeFlix.controller.OMDbAPIController;
|
||||||
import kellerkinder.HomeFlix.controller.UpdateController;
|
import kellerkinder.HomeFlix.controller.UpdateController;
|
||||||
import kellerkinder.HomeFlix.datatypes.SourceDataType;
|
import kellerkinder.HomeFlix.datatypes.SourceDataType;
|
||||||
|
import kellerkinder.HomeFlix.player.Player;
|
||||||
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
|
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
|
||||||
|
|
||||||
public class MainWindowController {
|
public class MainWindowController {
|
||||||
|
@ -228,6 +229,7 @@ public class MainWindowController {
|
||||||
private boolean settingsTrue = false;
|
private boolean settingsTrue = false;
|
||||||
private boolean autoUpdate = false;
|
private boolean autoUpdate = false;
|
||||||
private boolean useBeta = false;
|
private boolean useBeta = false;
|
||||||
|
private boolean betaPlayer = false;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
||||||
private int hashA = -647380320;
|
private int hashA = -647380320;
|
||||||
|
|
||||||
|
@ -545,42 +547,47 @@ public class MainWindowController {
|
||||||
@FXML
|
@FXML
|
||||||
private void playbtnclicked() {
|
private void playbtnclicked() {
|
||||||
// TODO rework when #19 is coming
|
// TODO rework when #19 is coming
|
||||||
|
|
||||||
if (System.getProperty("os.name").contains("Linux")) {
|
if (betaPlayer) {
|
||||||
String line;
|
new Player(streamUrl);
|
||||||
String output = "";
|
} else {
|
||||||
Process p;
|
if (System.getProperty("os.name").contains("Linux")) {
|
||||||
try {
|
String line;
|
||||||
p = Runtime.getRuntime().exec("which vlc");
|
String output = "";
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
Process p;
|
||||||
while ((line = input.readLine()) != null) {
|
|
||||||
output = line;
|
|
||||||
}
|
|
||||||
LOGGER.info(output);
|
|
||||||
input.close();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
if (output.contains("which: no vlc") || output == "") {
|
|
||||||
JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", vlcNotInstalled, dialogBtnStyle, main.getPrimaryStage());
|
|
||||||
vlcInfoAlert.showAndWait();
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec(new String[] { "vlc", streamUrl }); // TODO switch to ProcessBuilder
|
p = Runtime.getRuntime().exec("which vlc");
|
||||||
|
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||||
|
while ((line = input.readLine()) != null) {
|
||||||
|
output = line;
|
||||||
|
}
|
||||||
|
LOGGER.info(output);
|
||||||
|
input.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
if (output.contains("which: no vlc") || output == "") {
|
||||||
|
JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", vlcNotInstalled, dialogBtnStyle, main.getPrimaryStage());
|
||||||
|
vlcInfoAlert.showAndWait();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Runtime.getRuntime().exec(new String[] { "vlc", streamUrl }); // TODO switch to ProcessBuilder
|
||||||
|
} catch (IOException e) {
|
||||||
|
showErrorMsg(errorPlay, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")) {
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().open(new File(streamUrl));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
showErrorMsg(errorPlay, e);
|
showErrorMsg(errorPlay, e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! ");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")) {
|
|
||||||
try {
|
|
||||||
Desktop.getDesktop().open(new File(streamUrl));
|
|
||||||
} catch (IOException e) {
|
|
||||||
showErrorMsg(errorPlay, e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package kellerkinder.HomeFlix.player;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.WindowEvent;
|
||||||
|
import kellerkinder.HomeFlix.application.Main;
|
||||||
|
|
||||||
|
public class Player {
|
||||||
|
|
||||||
|
private PlayerController playerController;
|
||||||
|
private Stage stage;
|
||||||
|
private AnchorPane pane;
|
||||||
|
|
||||||
|
public Player(String file) {
|
||||||
|
try {
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(ClassLoader.getSystemResource("fxml/PlayerWindow.fxml"));
|
||||||
|
pane = (AnchorPane) fxmlLoader.load();
|
||||||
|
stage = new Stage();
|
||||||
|
stage.setScene(new Scene(pane));
|
||||||
|
stage.setTitle("HomeFlix");
|
||||||
|
stage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png")));
|
||||||
|
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
||||||
|
public void handle(WindowEvent we) {
|
||||||
|
playerController.getMediaPlayer().stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
playerController = fxmlLoader.getController();
|
||||||
|
playerController.init(file, this);
|
||||||
|
|
||||||
|
stage.setFullScreen(true);
|
||||||
|
stage.show();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stage getStage() {
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Parent getPane() {
|
||||||
|
return pane;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package kellerkinder.HomeFlix.player;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.property.DoubleProperty;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.media.Media;
|
||||||
|
import javafx.scene.media.MediaPlayer;
|
||||||
|
import javafx.scene.media.MediaPlayer.Status;
|
||||||
|
import javafx.scene.media.MediaView;
|
||||||
|
|
||||||
|
public class PlayerController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private MediaView mediaView;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private HBox controllsHBox;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton playBtn;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton fullscreenBtn;
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
private Media media;
|
||||||
|
private MediaPlayer mediaPlayer;
|
||||||
|
|
||||||
|
public void init(String file, Player player) {
|
||||||
|
this.player = player;
|
||||||
|
|
||||||
|
media = new Media(new File(file).toURI().toString());
|
||||||
|
mediaPlayer = new MediaPlayer(media);
|
||||||
|
mediaView.setMediaPlayer(mediaPlayer);
|
||||||
|
|
||||||
|
final DoubleProperty width = mediaView.fitWidthProperty();
|
||||||
|
final DoubleProperty height = mediaView.fitHeightProperty();
|
||||||
|
|
||||||
|
width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
|
||||||
|
height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
|
||||||
|
|
||||||
|
mediaView.setPreserveRatio(true);
|
||||||
|
mediaPlayer.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void fullscreenBtnAction(ActionEvent event) {
|
||||||
|
if (player.getStage().isFullScreen()) {
|
||||||
|
player.getStage().setFullScreen(false);
|
||||||
|
} else {
|
||||||
|
player.getStage().setFullScreen(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void playBtnAction(ActionEvent event) {
|
||||||
|
|
||||||
|
if (mediaPlayer.getStatus().equals(Status.PLAYING)) {
|
||||||
|
mediaPlayer.pause();
|
||||||
|
} else {
|
||||||
|
mediaPlayer.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaPlayer getMediaPlayer() {
|
||||||
|
return mediaPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.JFXButton?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.media.MediaView?>
|
||||||
|
|
||||||
|
<AnchorPane prefHeight="720.0" prefWidth="1280.0" style="-fx-background-color: black;" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kellerkinder.HomeFlix.player.PlayerController">
|
||||||
|
<children>
|
||||||
|
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<MediaView fx:id="mediaView" />
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<HBox fx:id="controllsHBox" alignment="CENTER" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<JFXButton fx:id="playBtn" onAction="#playBtnAction" prefHeight="39.0" prefWidth="75.0" style="-fx-background-color: white;" text="play" />
|
||||||
|
<JFXButton fx:id="fullscreenBtn" onAction="#fullscreenBtnAction" prefHeight="39.0" style="-fx-background-color: white;" text="fullscreen" />
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
Loading…
Reference in New Issue