updates to load gst in background

This commit is contained in:
Greg DiCristofaro 2022-02-11 11:04:23 -05:00
parent d8241caa60
commit 42a7844b2f

View File

@ -509,7 +509,7 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
* Thread that extracts a file and initializes all of the playback * Thread that extracts a file and initializes all of the playback
* components. * components.
*/ */
private class ExtractMedia extends SwingWorker<Void, Void> { private class ExtractMedia extends SwingWorker<GstStatus, Void> {
private ProgressHandle progress; private ProgressHandle progress;
private final AbstractFile sourceFile; private final AbstractFile sourceFile;
@ -521,7 +521,20 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
} }
@Override @Override
protected Void doInBackground() throws Exception { protected GstStatus doInBackground() throws Exception {
if (this.isCancelled()) {
throw new InterruptedException("Thread has been interrupted");
}
GstStatus loadStatus = GstLoader.tryLoad();
if (loadStatus == GstStatus.FAILURE) {
return loadStatus;
}
if (this.isCancelled()) {
throw new InterruptedException("Thread has been interrupted");
}
if (!tempFile.exists() || tempFile.length() < sourceFile.getSize()) { if (!tempFile.exists() || tempFile.length() < sourceFile.getSize()) {
progress = ProgressHandle.createHandle(NbBundle.getMessage(MediaPlayerPanel.class, "GstVideoPanel.ExtractMedia.progress.buffering", sourceFile.getName()), () -> this.cancel(true)); progress = ProgressHandle.createHandle(NbBundle.getMessage(MediaPlayerPanel.class, "GstVideoPanel.ExtractMedia.progress.buffering", sourceFile.getName()), () -> this.cancel(true));
@ -539,7 +552,7 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
progress.finish(); progress.finish();
} }
} }
return null; return loadStatus;
} }
/* /*
@ -553,18 +566,16 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
@Override @Override
protected void done() { protected void done() {
try { try {
super.get();
if (this.isCancelled()) { if (this.isCancelled()) {
return; return;
} }
GstStatus loadStatus = GstLoader.tryLoad(); GstStatus loadStatus = super.get();
if (loadStatus == GstStatus.FAILURE) { if (loadStatus == null || loadStatus == GstStatus.FAILURE) {
MessageNotifyUtil.Message.error(Bundle.MediaPlayerPanel_playbackDisabled()); return;
}
// This will disable the panel for future use. if (this.isCancelled()) {
IS_GST_ENABLED = false;
return; return;
} }
@ -662,7 +673,7 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
* thumb at the given width and height. It also paints the track blue as * thumb at the given width and height. It also paints the track blue as
* the thumb progresses. * the thumb progresses.
* *
* @param slider JSlider component * @param slider JSlider component
* @param thumbDimension * @param thumbDimension
*/ */
public CircularJSliderUI(JSlider slider, Dimension thumbDimension) { public CircularJSliderUI(JSlider slider, Dimension thumbDimension) {