-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoAnalysisManager.java
More file actions
78 lines (63 loc) · 2.97 KB
/
Copy pathVideoAnalysisManager.java
File metadata and controls
78 lines (63 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import javafx.concurrent.Task;
import javafx.application.Platform;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class VideoAnalysisManager {
private static final int MAX_THREADS = 4; // Anzahl gleichzeitiger Threads
private final ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS);
@FXML
private ProgressBar progressBar;
@FXML
private TableView<KnkMedia> playList; // Die Tabelle mit allen Videos
public void analyzeAllVideos() {
List<KnkMedia> mediaList = playList.getItems(); // Hole alle Videos aus der Playlist
if (mediaList.isEmpty()) {
LOGGER.info("Keine Videos in der Playlist vorhanden.");
return;
}
AtomicInteger completedTasks = new AtomicInteger(0); // Zähler für abgeschlossene Aufgaben
int totalTasks = mediaList.size(); // Gesamte Anzahl der Videos
// Zeigt an, dass die ProgressBar aktiv ist
Platform.runLater(() -> {
progressBar.setVisible(true);
progressBar.setProgress(0); // Anfangszustand
});
// Für jedes Video eine Aufgabe erstellen
for (KnkMedia media : mediaList) {
Task<Void> task = new Task<>() {
@Override
protected Void call() throws Exception {
LOGGER.info("Starte Analyse für: " + media.getName());
personDetector.analyze(media); // Video analysieren (Dein bestehender Code)
LOGGER.info("Analyse abgeschlossen für: " + media.getName());
// Fortschritt aktualisieren
int finished = completedTasks.incrementAndGet();
updateProgress(finished, totalTasks);
return null;
}
};
// Fortschritt an ProgressBar binden
task.progressProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> progressBar.setProgress((double) completedTasks.get() / totalTasks));
});
task.setOnFailed(e -> LOGGER.error("Fehler bei der Analyse von " + media.getName(), task.getException()));
// Aufgabe dem Thread-Pool hinzufügen
executor.submit(task);
}
// Stoppe den ProgressBar, wenn alle Aufgaben abgeschlossen sind
new Thread(() -> {
try {
executor.shutdown();
while (!executor.isTerminated()) {
Thread.sleep(100); // Warte, bis alle Tasks abgeschlossen sind
}
Platform.runLater(() -> progressBar.setVisible(false)); // Fortschrittsbalken verstecken
LOGGER.info("Alle Analysen abgeschlossen.");
} catch (InterruptedException e) {
LOGGER.error("Fehler beim Warten auf Task-Abschluss", e);
}
}).start();
}
}