Estou com um problema ao utilizar Media View usando java FX.
Eu consegui implementar todo o codigo porém o video executa ouço o audio mais ele nao aparece em minha janela.
O que estou fazendo de errado ?
`package termoplayer;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import termoplayer.model.Person;
import termoplayer.view.PersonOverviewController;
import java.io.File;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
public class MainApp extends Application {
private Stage primaryStage;
/*
private static String workingDir = System.getProperty("user.dir");
private static File f = new File(workingDir, "src\\videoteste.mp4");
private static Media m = new Media(f.toURI().toString());
private static MediaPlayer mp = new MediaPlayer(m);
@FXML
MediaView mv = new MediaView(mp);
@FXML
Label lblLabel; //= new Label();
*/
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("TermoPlayer Itaipava");
initRootLayout();
showPersonOverview();
Person person = new Person();
}
/*
mv.setPreserveRatio(true);
mp.setCycleCount(MediaPlayer.INDEFINITE);
mp.play();
//lblLabel.setText("51");
//Thread t1 = new Thread(new VerificaSerial());
//t1.start() ;
}
/**
* Inicializa o root layout (layout base).
*/
public void initRootLayout() {
try {
// Carrega o root layout do arquivo fxml.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
PersonOverviewController.rootLayout = (BorderPane) loader.load();
// Mostra a scene (cena) contendo o root layout.
Scene scene = new Scene(PersonOverviewController.rootLayout);
//PersonOverviewController.rootLayout.getChildren().add(PersonOverviewController.mv);
primaryStage.setScene(scene);
primaryStage.setFullScreen(true);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Mostra o person overview dentro do root layout.
*/
public void showPersonOverview() {
try {
// Carrega o person overview.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/PersonOverview.fxml"));
AnchorPane personOverview = (AnchorPane) loader.load();
// Define o person overview dentro do root layout.
PersonOverviewController.rootLayout.setCenter(personOverview);
// Dá ao controlador acesso à the main app.
PersonOverviewController controller = loader.getController();
controller.setMainApp(this);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Retorna o palco principal.
*
* @return
*/
public static void main(String[] args) {
launch(args);
System.out.println("Finaliza aqui ");
}
public void setPrimaryStage(Stage primaryStage) {
this.primaryStage = primaryStage;
}
public Stage getPrimaryStage() {
return primaryStage;
}
}`
Person.java
`package termoplayer.model;
import java.io.File;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import termoplayer.MainApp;
import termoplayer.view.PersonOverviewController;
public class Person {
private static String workingDir = System.getProperty("user.dir");
private static File f = new File(workingDir, "src\\videoteste.mp4");
private static Media m = new Media(f.toURI().toString());
private static MediaPlayer mp = new MediaPlayer(m);
//@FXML
//MediaView mv = new MediaView(mp);
//@FXML
//private Label lblLabel;
/**
* Construtor padrão.
*/
public Person() {
// this(null, null);
// PersonOverviewController.mv.setPreserveRatio(true);
//PersonOverviewController.rootLayout.getChildren().add(PersonOverviewController.mv);
mp.setCycleCount(MediaPlayer.INDEFINITE);
mp.play();
}
/**
* Construtor com alguns dados iniciais.
*
*
*/
public Person(File f, MediaPlayer mp) {
//MainApp.rootLayout.getChildren().add(PersonOverviewController.mv);
//PersonOverviewController.mv.setPreserveRatio(true);
mp.setCycleCount(MediaPlayer.INDEFINITE);
mp.play();
}
public static String getWorkingDir() {
return workingDir;
}
public static void setWorkingDir(String workingDir) {
Person.workingDir = workingDir;
}
public static File getF() {
return f;
}
public static void setF(File f) {
Person.f = f;
}
public static Media getM() {
return m;
}
public static void setM(Media m) {
Person.m = m;
}
public static MediaPlayer getMp() {
return mp;
}
public static void setMp(MediaPlayer mp) {
Person.mp = mp;
}
}`
PersonOverviewController.java
`package termoplayer.view;
import java.awt.Label;
import javafx.fxml.FXML;
import javafx.scene.layout.BorderPane;
import javafx.scene.media.MediaView;
import termoplayer.MainApp;
public class PersonOverviewController {
private MainApp mainApp;
@FXML
public static MediaView mv;
@FXML
private Label lblLabel;
@FXML
public static BorderPane rootLayout;
/**
* O construtor.
* O construtor é chamado antes do método inicialize().
*/
public PersonOverviewController() {
//PersonOverviewController.mv.setPreserveRatio(true);
//rootLayout.getChildren().add(PersonOverviewController.mv);
}
public static MediaView getMv() {
return mv;
}
public static void setMv(MediaView mv) {
PersonOverviewController.mv = mv;
}
public Label getLblLabel() {
return lblLabel;
}
public void setLblLabel(Label lblLabel) {
this.lblLabel = lblLabel;
}
public static BorderPane getRootLayout() {
return rootLayout;
}
public static void setRootLayout(BorderPane rootLayout) {
PersonOverviewController.rootLayout = rootLayout;
}
/**
* Inicializa a classe controller. Este método é chamado automaticamente
* após o arquivo fxml ter sido carregado.
*/
@FXML
private void initialize() {
// Inicializa a tablea de pessoa com duas colunas.
//PersonOverviewController.mv.setPreserveRatio(true);
//MainApp.rootLayout.getChildren().add(PersonOverviewController.mv);
//rootLayout.getChildren().add(PersonOverviewController.mv);
/**
* É chamado pela aplicação principal para dar uma referência de volta a si mesmo.
*
* @param mainApp
*/
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
}
}`
PersonOverview.fxml
`<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?> <?import javafx.scene.control.*?> <?import javafx.scene.media.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.AnchorPane?> `