forked from j62/ctbrec
Add possibility to switch back to best stream quality
This commit is contained in:
parent
643650d69e
commit
f312d5ed58
|
@ -17,21 +17,26 @@ import javafx.scene.image.Image;
|
|||
import javafx.stage.Stage;
|
||||
|
||||
public class StreamSourceSelectionDialog {
|
||||
private static final StreamSource BEST = new BestStreamSource();
|
||||
|
||||
private StreamSourceSelectionDialog() {}
|
||||
|
||||
public static void show(Scene parent, Model model, Function<Model,Void> onSuccess, Function<Throwable, Void> onFail) {
|
||||
Task<List<StreamSource>> selectStreamSource = new Task<List<StreamSource>>() {
|
||||
@Override
|
||||
protected List<StreamSource> call() throws Exception {
|
||||
List<StreamSource> sources = model.getStreamSources();
|
||||
Collections.sort(sources);
|
||||
sources.add(BEST);
|
||||
return sources;
|
||||
}
|
||||
};
|
||||
selectStreamSource.setOnSucceeded((e) -> {
|
||||
selectStreamSource.setOnSucceeded(e -> {
|
||||
List<StreamSource> sources;
|
||||
try {
|
||||
sources = selectStreamSource.get();
|
||||
int selectedIndex = model.getStreamUrlIndex() > -1 ? Math.min(model.getStreamUrlIndex(), sources.size()-1) : sources.size()-1;
|
||||
ChoiceDialog<StreamSource> choiceDialog = new ChoiceDialog<StreamSource>(sources.get(selectedIndex), sources);
|
||||
ChoiceDialog<StreamSource> choiceDialog = new ChoiceDialog<>(sources.get(selectedIndex), sources);
|
||||
choiceDialog.setTitle("Stream Quality");
|
||||
choiceDialog.setHeaderText("Select your preferred stream quality");
|
||||
choiceDialog.setResizable(true);
|
||||
|
@ -41,17 +46,28 @@ public class StreamSourceSelectionDialog {
|
|||
stage.getIcons().add(new Image(icon));
|
||||
Optional<StreamSource> selectedSource = choiceDialog.showAndWait();
|
||||
if(selectedSource.isPresent()) {
|
||||
int index = sources.indexOf(selectedSource.get());
|
||||
int index = -1;
|
||||
if (selectedSource.get() != BEST) {
|
||||
index = sources.indexOf(selectedSource.get());
|
||||
}
|
||||
model.setStreamUrlIndex(index);
|
||||
onSuccess.apply(model);
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e1) {
|
||||
} catch (ExecutionException e1) {
|
||||
onFail.apply(e1);
|
||||
} catch (InterruptedException e1) {
|
||||
Thread.currentThread().interrupt();
|
||||
onFail.apply(e1);
|
||||
}
|
||||
});
|
||||
selectStreamSource.setOnFailed((e) -> {
|
||||
onFail.apply(selectStreamSource.getException());
|
||||
});
|
||||
selectStreamSource.setOnFailed(e -> onFail.apply(selectStreamSource.getException()));
|
||||
new Thread(selectStreamSource).start();
|
||||
}
|
||||
|
||||
private static class BestStreamSource extends StreamSource {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Best";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue