Gluonhq VideoService

时间:2018-01-07 16:41:44

标签: javafxports

我正在开发一个媒体播放器应用程序,我正在使用VideoService用于此目的,我的问题是应用程序生命周期,当它在背景中最小化,同时首先播放它的暂停视频,我在暂停处理程序中处理这个,当我最大化我打电话给videoservice.play(),但它播放了一秒钟,整个应用程序陷入黑屏并最终崩溃。 如果我不打电话给videoservice.play它会崩溃,这是我的示例代码。

private void initVideoService(VideoService service) {
    videoService = service;
    videoService.setPosition(Pos.CENTER, 0, 40, 0, 40);
    videoService.setControlsVisible(true);
    videoService.fullScreenProperty().addListener((obs, ov, nv) -> MobileApplication.getInstance().getAppBar().setVisible(!nv));    MobileApplication.getInstance().getAppBar().getActionItems().addAll(playButton, stopButton, fullScreenButton);
    videoService.statusProperty().addListener((obs, ov, nv) -> {
        System.out.println(String.format("FullScreenCondition : %b", nv != MediaPlayer.Status.PLAYING && nv != MediaPlayer.Status.PAUSED));
        fullScreenButton.setDisable(nv != MediaPlayer.Status.PLAYING && nv != MediaPlayer.Status.PAUSED);
        if (videoService.statusProperty().get() == MediaPlayer.Status.PLAYING) {
            System.out.println("Video is Playing");
            playButton.setGraphic(MaterialDesignIcon.PAUSE.graphic());
            videoService.setFullScreen(true);
        } else if (videoService.statusProperty().get() == MediaPlayer.Status.PAUSED) {
            System.out.println("Video is paused");
            playButton.setGraphic(MaterialDesignIcon.PLAY_ARROW.graphic());
            videoService.setFullScreen(false);
        } else {
            System.out.println("Video is Stopped");
            playButton.setGraphic(MaterialDesignIcon.PLAY_ARROW.graphic());
            videoService.setFullScreen(false);
        }
    });
    Services.get(LifecycleService.class).ifPresent(s -> {
        s.addListener(LifecycleEvent.PAUSE, () -> {
            System.out.println("paused");
            videoService.pause();
        });
        s.addListener(LifecycleEvent.RESUME, () -> {
            System.out.println("Resumed");
            videoService.play();
        });
    });
} 
public void navToEpisode(Episode epi) {
    Services.get(VideoService.class).ifPresent(service -> {
        initVideoService(service);
    });
    RestClient.execute(new RestOperation() {
        @Override
        public void run() {
            String videoDownloadLink = RestUtils.getVideoDownloadLink(epi.getLinkToEpisode());
            try {
                publish(() ->
                {
                    if (Platform.isAndroid() || Platform.isIOS()) {
                        videoService.getPlaylist().add(videoDownloadLink);
                        videoService.play();
                    }
                });

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });
}

0 个答案:

没有答案