本文介绍了JavaFX- MediaView不显示视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我要播放所选视频的场景上有一个MediaView.视频正在播放,我可以听到声音,但看不到声音.

I have a MediaView on the scene in which I am trying to play the selected video. The video is playing, I can hear the sound, but it's not visible.

这是我的代码:

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

    }

});

推荐答案

排序:代替:

videoPlayer = new MediaView(mp);

您应该这样做:

videoPlayer.setMediaPlayer(mp);

这篇关于JavaFX- MediaView不显示视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 08:18