Browse Source

added first version of the new player

* added a javafx mediaplayer based player
pull/24/head
Jannik 4 years ago
parent
commit
2881c1f9d6
  1. 65
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  2. 52
      src/main/java/kellerkinder/HomeFlix/player/Player.java
  3. 75
      src/main/java/kellerkinder/HomeFlix/player/PlayerController.java
  4. 26
      src/main/resources/fxml/PlayerWindow.fxml

65
src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java

@ -97,6 +97,7 @@ import kellerkinder.HomeFlix.controller.DBController;
import kellerkinder.HomeFlix.controller.OMDbAPIController;
import kellerkinder.HomeFlix.controller.UpdateController;
import kellerkinder.HomeFlix.datatypes.SourceDataType;
import kellerkinder.HomeFlix.player.Player;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
public class MainWindowController {
@ -228,6 +229,7 @@ public class MainWindowController {
private boolean settingsTrue = false;
private boolean autoUpdate = false;
private boolean useBeta = false;
private boolean betaPlayer = false;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
private int hashA = -647380320;
@ -545,42 +547,47 @@ public class MainWindowController {
@FXML
private void playbtnclicked() {
// TODO rework when #19 is coming
if (System.getProperty("os.name").contains("Linux")) {
String line;
String output = "";
Process p;
try {
p = Runtime.getRuntime().exec("which vlc");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output = line;
if (betaPlayer) {
new Player(streamUrl);
} else {
if (System.getProperty("os.name").contains("Linux")) {
String line;
String output = "";
Process p;
try {
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();
}
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 {
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 {
Runtime.getRuntime().exec(new String[] { "vlc", streamUrl }); // TODO switch to ProcessBuilder
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! ");
}
} 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

52
src/main/java/kellerkinder/HomeFlix/player/Player.java

@ -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;
}
}

75
src/main/java/kellerkinder/HomeFlix/player/PlayerController.java

@ -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;
}
}

26
src/main/resources/fxml/PlayerWindow.fxml

@ -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…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close