Add open in player to menu in "Recording" tab

This commit is contained in:
0xboobface 2018-11-17 14:35:03 +01:00
parent 549181f5ed
commit f7c581a517
3 changed files with 52 additions and 30 deletions

View File

@ -2,16 +2,22 @@ package ctbrec.ui;
import java.io.File;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Hmac;
import ctbrec.Model;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.DevNull;
import ctbrec.io.StreamRedirectThread;
import ctbrec.recorder.download.StreamSource;
import javafx.application.Platform;
import javafx.scene.control.Alert;
public class Player {
private static final transient Logger LOG = LoggerFactory.getLogger(Player.class);
@ -43,6 +49,39 @@ public class Player {
}
}
public static void play(Model model) {
try {
if(model.isOnline(true)) {
boolean singlePlayer = Config.getInstance().getSettings().singlePlayer;
if (singlePlayer && playerThread != null && playerThread.isRunning()) {
playerThread.stopThread();
}
List<StreamSource> sources = model.getStreamSources();
Collections.sort(sources);
StreamSource best = sources.get(sources.size()-1);
LOG.debug("Playing {}", best.getMediaPlaylistUrl());
Player.play(best.getMediaPlaylistUrl());
} else {
Platform.runLater(() -> {
Alert alert = new AutosizeAlert(Alert.AlertType.INFORMATION);
alert.setTitle("Room not public");
alert.setHeaderText("Room is currently not public");
alert.showAndWait();
});
}
} catch (Exception e1) {
LOG.error("Couldn't get stream information for model {}", model, e1);
Platform.runLater(() -> {
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Couldn't determine stream URL");
alert.setContentText(e1.getLocalizedMessage());
alert.showAndWait();
});
}
}
public static void stop() {
if (playerThread != null) {
playerThread.stopThread();

View File

@ -315,16 +315,24 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
MenuItem openInBrowser = new MenuItem("Open in Browser");
openInBrowser.setOnAction((e) -> DesktopIntegration.open(selectedModel.getUrl()));
MenuItem openInPlayer = new MenuItem("Open in Player");
openInPlayer.setOnAction((e) -> Player.play(selectedModel.getUrl()));
openInPlayer.setOnAction((e) -> openInPlayer(selectedModel));
MenuItem switchStreamSource = new MenuItem("Switch resolution");
switchStreamSource.setOnAction((e) -> switchStreamSource(selectedModel));
ContextMenu menu = new ContextMenu(stop);
menu.getItems().add(selectedModel.isSuspended() ? resumeRecording : pauseRecording);
menu.getItems().addAll(copyUrl, openInBrowser, switchStreamSource);
menu.getItems().addAll(copyUrl, openInPlayer, openInBrowser, switchStreamSource);
return menu;
}
private void openInPlayer(JavaFxModel selectedModel) {
table.setCursor(Cursor.WAIT);
new Thread(() -> {
Player.play(selectedModel);
Platform.runLater(() -> table.setCursor(Cursor.DEFAULT));
}).start();
}
private void switchStreamSource(JavaFxModel fxModel) {
try {
if(!fxModel.isOnline()) {

View File

@ -2,8 +2,6 @@ package ctbrec.ui;
import java.io.EOFException;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@ -17,7 +15,6 @@ import com.iheartradio.m3u8.ParseException;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.recorder.Recorder;
import ctbrec.recorder.download.StreamSource;
import javafx.animation.FadeTransition;
import javafx.animation.FillTransition;
import javafx.animation.ParallelTransition;
@ -300,32 +297,10 @@ public class ThumbCell extends StackPane {
}
void startPlayer() {
setCursor(Cursor.WAIT);
new Thread(() -> {
try {
if(model.isOnline(true)) {
List<StreamSource> sources = model.getStreamSources();
Collections.sort(sources);
StreamSource best = sources.get(sources.size()-1);
LOG.debug("Playing {}", best.getMediaPlaylistUrl());
Player.play(best.getMediaPlaylistUrl());
} else {
Platform.runLater(() -> {
Alert alert = new AutosizeAlert(Alert.AlertType.INFORMATION);
alert.setTitle("Room not public");
alert.setHeaderText("Room is currently not public");
alert.showAndWait();
});
}
} catch (Exception e1) {
LOG.error("Couldn't get stream information for model {}", model, e1);
Platform.runLater(() -> {
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Couldn't determine stream URL");
alert.setContentText(e1.getLocalizedMessage());
alert.showAndWait();
});
}
Player.play(model);
Platform.runLater(() -> setCursor(Cursor.DEFAULT));
}).start();
}