added first version of the new player
* added a javafx mediaplayer based player
This commit is contained in:
52
src/main/java/kellerkinder/HomeFlix/player/Player.java
Normal file
52
src/main/java/kellerkinder/HomeFlix/player/Player.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user