VLCJ播放器在JavaFX场景中崩溃

问题描述 投票:0回答:1

我需要一个带有FXML的JavaFX场景上的多个播放器来做一个CCTV监视系统,以显示实时摄像机的流。

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import java.net.URL;
import java.util.ResourceBundle;

import static uk.co.caprica.vlcj.javafx.videosurface.ImageViewVideoSurfaceFactory.videoSurfaceForImageView;


public class allCamerasMainGridScreenController implements Initializable {
    public MediaPlayerFactory mediaPlayerFactory;
    public  EmbeddedMediaPlayer embeddedMediaPlayer;

    @FXML BorderPane mainBorderPane;
    @FXML GridPane cameraViewGrid;


    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
            ImageView cameraView = new ImageView();
            mediaPlayerFactory = new MediaPlayerFactory();
            embeddedMediaPlayer = mediaPlayerFactory.mediaPlayers().newEmbeddedMediaPlayer();
            cameraView.setPreserveRatio(true);
            cameraView.setFitHeight(340);
            embeddedMediaPlayer.videoSurface().set(videoSurfaceForImageView(cameraView));
            cameraViewGrid.add(cameraView,0,0);
            embeddedMediaPlayer.media().play("http://10.0.0.6:8081");
    }

}

使用此代码,我可以使播放器运行,但是几秒钟后它崩溃了,并在IntelliJ上抛出了此消息

Process finished with exit code -1073741819 (0xC0000005)

java javafx vlcj
1个回答
0
投票

感谢caprica,实际上这是一个意外的垃圾收集,我能够通过将staticMediaPlayerFactory声明为EmbeddedMediaPlayer来解决它。

然后在代码上显示如下:

public static MediaPlayerFactory mediaPlayerFactory;
public static EmbeddedMediaPlayer embeddedMediaPlayer;
© www.soinside.com 2019 - 2024. All rights reserved.