Improve error handling in the StreamPreview
This commit is contained in:
parent
f75687752c
commit
3d7fc64bf5
|
@ -88,6 +88,7 @@ public class StreamPreview extends StackPane {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
LOG.debug("Preview url for {} is {}", model.getName(), best.getMediaPlaylistUrl());
|
LOG.debug("Preview url for {} is {}", model.getName(), best.getMediaPlaylistUrl());
|
||||||
video = new Media(best.getMediaPlaylistUrl());
|
video = new Media(best.getMediaPlaylistUrl());
|
||||||
|
video.setOnError(() -> onError(videoPlayer));
|
||||||
if(videoPlayer != null) {
|
if(videoPlayer != null) {
|
||||||
videoPlayer.dispose();
|
videoPlayer.dispose();
|
||||||
}
|
}
|
||||||
|
@ -128,8 +129,8 @@ public class StreamPreview extends StackPane {
|
||||||
// future has been canceled, that's fine
|
// future has been canceled, that's fine
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("Couldn't start preview video: {}", e.getMessage());
|
LOG.warn("Couldn't start preview video: {}", e.getMessage());
|
||||||
showTestImage();
|
|
||||||
}
|
}
|
||||||
|
showTestImage();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Couldn't start preview video: {}", e.getMessage());
|
LOG.warn("Couldn't start preview video: {}", e.getMessage());
|
||||||
showTestImage();
|
showTestImage();
|
||||||
|
@ -146,12 +147,14 @@ public class StreamPreview extends StackPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if(future != null && !future.isDone()) {
|
MediaPlayer old = videoPlayer;
|
||||||
future.cancel(true);
|
Future<?> oldFuture = future;
|
||||||
}
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
if(videoPlayer != null) {
|
if(oldFuture != null && !oldFuture.isDone()) {
|
||||||
videoPlayer.dispose();
|
oldFuture.cancel(true);
|
||||||
|
}
|
||||||
|
if(old != null) {
|
||||||
|
old.dispose();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -161,13 +164,11 @@ public class StreamPreview extends StackPane {
|
||||||
if(videoPlayer.getError().getCause() != null) {
|
if(videoPlayer.getError().getCause() != null) {
|
||||||
LOG.error("Error while starting preview stream root cause:", videoPlayer.getError().getCause());
|
LOG.error("Error while starting preview stream root cause:", videoPlayer.getError().getCause());
|
||||||
}
|
}
|
||||||
stop();
|
showTestImage();
|
||||||
Platform.runLater(() -> {
|
|
||||||
showTestImage();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showTestImage() {
|
private void showTestImage() {
|
||||||
|
stop();
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
videoPreview.setVisible(false);
|
videoPreview.setVisible(false);
|
||||||
Image img = new Image(getClass().getResource("/image_not_found.png").toString(), true);
|
Image img = new Image(getClass().getResource("/image_not_found.png").toString(), true);
|
||||||
|
|
Loading…
Reference in New Issue