1
我在我試圖播放選定視頻的場景中有一個MediaView。視頻正在播放,我可以聽到聲音,但它不可見。JavaFX- MediaView不顯示視頻
這裏是我的代碼:
playLocalVideo.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
File fileToPlay = null;
//DirectoryChooser directoryChooser = new DirectoryChooser();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Select Files to Upload");
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("VIDEO files (*.mp4)", "*.mp4");
fileChooser.getExtensionFilters().add(extFilter);
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
try {
fileToPlay = fileChooser.showOpenDialog(stage).getCanonicalFile();
Media m = new Media(fileToPlay.toURI().toString());
MediaPlayer mp = new MediaPlayer(m);
videoPlayer = new MediaView(mp);
videoPlayer.setPreserveRatio(true);
mp.play();
} catch (IOException ex) {
Logger.getLogger(TutorControlPanelController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});