Made YouTube video upload asynchronous from the GUI
This commit is contained in:
@@ -184,11 +184,14 @@ public class GuiYoutubeUpload extends GuiScreen {
|
|||||||
uploadButton.setEnabled();
|
uploadButton.setEnabled();
|
||||||
if (uploading) {
|
if (uploading) {
|
||||||
uploadButton.onClick(() -> {
|
uploadButton.onClick(() -> {
|
||||||
try {
|
setState(false);
|
||||||
upload.cancel();
|
new Thread(() -> {
|
||||||
} catch (InterruptedException e) {
|
try {
|
||||||
e.printStackTrace();
|
upload.cancel();
|
||||||
}
|
} catch(InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}).setI18nLabel("replaymod.gui.cancel");
|
}).setI18nLabel("replaymod.gui.cancel");
|
||||||
} else {
|
} else {
|
||||||
uploadButton.onClick(() -> {
|
uploadButton.onClick(() -> {
|
||||||
@@ -219,8 +222,9 @@ public class GuiYoutubeUpload extends GuiScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
if (t instanceof InterruptedException) {
|
if (t instanceof InterruptedException || upload.isCancelled()) {
|
||||||
progressBar.setLabel("0%");
|
progressBar.setProgress(0);
|
||||||
|
progressBar.setLabel("%d%%");
|
||||||
} else {
|
} else {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
progressBar.setLabel(t.getLocalizedMessage());
|
progressBar.setLabel(t.getLocalizedMessage());
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ public class YoutubeUploader {
|
|||||||
@Getter
|
@Getter
|
||||||
private State state;
|
private State state;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private volatile boolean cancelled;
|
||||||
|
|
||||||
public YoutubeUploader(Minecraft minecraft, File videoFile, int videoFrames,
|
public YoutubeUploader(Minecraft minecraft, File videoFile, int videoFrames,
|
||||||
String thumbnailFormat, byte[] thumbnailImage,
|
String thumbnailFormat, byte[] thumbnailImage,
|
||||||
RenderSettings settings, VideoVisibility videoVisibility, VideoSnippet videoSnippet)
|
RenderSettings settings, VideoVisibility videoVisibility, VideoSnippet videoSnippet)
|
||||||
@@ -78,6 +81,8 @@ public class YoutubeUploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ListenableFuture<Video> upload() throws IOException {
|
public ListenableFuture<Video> upload() throws IOException {
|
||||||
|
cancelled = false;
|
||||||
|
|
||||||
final SettableFuture<Video> future = SettableFuture.create();
|
final SettableFuture<Video> future = SettableFuture.create();
|
||||||
thread = new Thread(() -> {
|
thread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@@ -108,9 +113,11 @@ public class YoutubeUploader {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//I blame the Google SDK for not supporting "proper" upload cancellation
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void cancel() throws InterruptedException {
|
public void cancel() throws InterruptedException {
|
||||||
thread.interrupt();
|
thread.stop();
|
||||||
thread.join();
|
cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Credential auth() throws IOException {
|
private Credential auth() throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user