4 changed files with 189 additions and 29 deletions
@ -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