I’m practicing and writing an application for working with video. I need to trim the video (And in the future take a frame from the moment in the video) but even at this stage I can’t package the application.
jpackage does not create and gives various errors, although when I try it on my other application, jpackage works fine
HelloApplication.java
package com.project;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Slider;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.io.File;
import java.io.IOException;
public class HelloApplication extends Application {
MediaPlayer mediaPlayer;
MediaView mediaView;
Media media;
Label timeLabel;
File file;
private Duration startTime;
private Duration endTime;
@Override
public void start(Stage stage) throws IOException {
stage.setTitle("Hello!");
stage.setWidth(1000);
stage.setHeight(800);
VBox generalBox = new VBox();
HBox selecter = new HBox(10);
Button buttonSelect = new Button("Выбрать");
Label labelSelect = new Label("Не выбрано");
selecter.getChildren().addAll(buttonSelect, labelSelect);
VBox videoBox = new VBox();
videoBox.setStyle("-fx-border-color: black; -fx-border-width: 2px;");
VBox.setVgrow(videoBox, Priority.ALWAYS);
StackPane videos = new StackPane();
mediaView = new MediaView();
videos.getChildren().add(mediaView);
videoBox.getChildren().addAll(videos);
//--------------------------------
VBox controllerBox = new VBox();
controllerBox.setStyle("-fx-border-color: red; -fx-border-width: 2px;");
HBox startBox = new HBox(10);
startBox.setStyle("-fx-border-color: blue; -fx-border-width: 2px;");
Button start = new Button("►");
start.setDisable(true);
startBox.getChildren().addAll(start);
HBox timeLine = new HBox(10);
timeLine.setStyle("-fx-border-color: green; -fx-border-width: 2px;");
ProgressBar progressBar = new ProgressBar(0);
progressBar.setPrefWidth(500);
timeLabel = new Label("00:00:00");
timeLine.getChildren().addAll(progressBar, timeLabel);
HBox sliders = new HBox();
sliders.setStyle("-fx-border-color: yellow; -fx-border-width: 2px;");
Button leftOne = new Button("←");
leftOne.setDisable(true);
Button leftFive = new Button("←←");
leftFive.setDisable(true);
Slider slider = new Slider(0, 100, 0);
slider.setPrefWidth(500);
slider.setDisable(true);
Button rightOne = new Button("→");
rightOne.setDisable(true);
Button rightFive = new Button("→→");
rightFive.setDisable(true);
sliders.getChildren().addAll(leftFive, leftOne, slider, rightOne, rightFive);
HBox setterButton = new HBox(10);
setterButton.setStyle("-fx-border-color: black; -fx-border-width: 2px;");
Button startButton = new Button("Начало");
startButton.setDisable(true);
Label startLabel = new Label("00:00:00");
Button endButton = new Button("Конец");
endButton.setDisable(true);
Label endLabel = new Label("00:00:00");
Button pruning = new Button("Обрезать");
pruning.setDisable(true);
setterButton.getChildren().addAll(startButton, startLabel, endButton, endLabel, pruning);
controllerBox.getChildren().addAll(startBox, timeLine, sliders, setterButton);
//----------------------------
generalBox.getChildren().addAll(selecter, videoBox, controllerBox);
Scene scene = new Scene(generalBox);
stage.setScene(scene);
stage.show();
//Обработчик кнопок
buttonSelect.setOnAction(e -> {
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Video Files", "*.mp4", "*.avi", "*.mkv"));
file = chooser.showOpenDialog(stage);
if(file != null){
if(mediaPlayer != null){
mediaPlayer.dispose();
}
media = new Media(file.toURI().toString());
mediaPlayer = new MediaPlayer(media);
TimerVideo videoTimer = new TimerVideo(mediaPlayer, timeLabel);
mediaPlayer.currentTimeProperty().addListener((observable, oldValue, newValue) -> {
Duration totalDuration = mediaPlayer.getTotalDuration();
if (totalDuration != null && !totalDuration.isUnknown()) {
double progress = newValue.toSeconds() / totalDuration.toSeconds();
progressBar.setProgress(progress);
}
});
mediaView.setMediaPlayer(mediaPlayer);
mediaView.setFitHeight(600);
mediaView.setFitWidth(300);
mediaView.setPreserveRatio(true);
labelSelect.setText("Выбрано "+ file.getAbsolutePath());
start.setDisable(false);
slider.setDisable(false);
startButton.setDisable(false);
endButton.setDisable(false);
pruning.setDisable(false);
rightFive.setDisable(false);
rightOne.setDisable(false);
leftFive.setDisable(false);
leftOne.setDisable(false);
mediaPlayer.currentTimeProperty().addListener((observable, oldValue, newValue) -> {
if (!slider.isValueChanging()) { // Проверяем, что пользователь не взаимодействует с слайдером
Duration totalDuration = mediaPlayer.getTotalDuration();
if (totalDuration != null && !totalDuration.isUnknown()) {
double progress = newValue.toSeconds() / totalDuration.toSeconds();
slider.setValue(progress * 100); // Обновляем слайдер (в процентах)
}
}
slider.valueChangingProperty().addListener((obs, wasChanging, isChanging) -> {
if (!isChanging) { // Когда пользователь отпускает слайдер
Duration totalDuration = mediaPlayer.getTotalDuration();
if (totalDuration != null) {
double newTime = slider.getValue() / 100 * totalDuration.toSeconds();
mediaPlayer.seek(Duration.seconds(newTime)); // Устанавливаем новую позицию воспроизведения
}
}
});
});
}
});
start.setOnAction(e -> {
if(mediaPlayer.getStatus() == MediaPlayer.Status.PLAYING){
mediaPlayer.pause();
start.setText("❚❚");
}else{
mediaPlayer.play();
start.setText("►");
}
});
startButton.setOnAction(e ->{
if(mediaPlayer != null){
startTime = mediaPlayer.getCurrentTime();
startLabel.setText(formatDuration(startTime));
}
});
endButton.setOnAction(e -> {
if(mediaPlayer != null){
endTime = mediaPlayer.getCurrentTime();
endLabel.setText(formatDuration(endTime));
}
});
leftOne.setOnAction(e ->{
double value = slider.getValue();
Duration totalDuration = mediaPlayer.getTotalDuration();
if(totalDuration != null) {
slider.setValue(value - 1);
double timeValue = slider.getValue() / 100 * totalDuration.toSeconds();
mediaPlayer.seek(Duration.seconds(timeValue));
}
});
leftFive.setOnAction(e ->{
double value = slider.getValue();
Duration totalDuration = mediaPlayer.getTotalDuration();
if(totalDuration != null) {
slider.setValue(value - 5);
double timeValue = slider.getValue() / 100 * totalDuration.toSeconds();
mediaPlayer.seek(Duration.seconds(timeValue));
}
});
rightFive.setOnAction(e ->{
double value = slider.getValue();
Duration totalDuration = mediaPlayer.getTotalDuration();
if(totalDuration != null) {
slider.setValue(value + 5);
double timeValue = slider.getValue() / 100 * totalDuration.toSeconds();
mediaPlayer.seek(Duration.seconds(timeValue));
}
});
rightOne.setOnAction(e ->{
double value = slider.getValue();
Duration totalDuration = mediaPlayer.getTotalDuration();
if(totalDuration != null) {
slider.setValue(value + 1);
double timeValue = slider.getValue() / 100 * totalDuration.toSeconds();
mediaPlayer.seek(Duration.seconds(timeValue));
}
});
pruning.setOnAction(e -> {
try {
// Получаем startTime и endTime как Duration
double startInSeconds = startTime.toMillis() / 1000.0; // Преобразуем миллисекунды в секунды
double endInSeconds = endTime.toMillis() / 1000.0; // Преобразуем миллисекунды в секунды
// Преобразуем путь к файлу в URI и генерируем новое имя для обрезанного видео
String name = file.toURI().toString();
String newName = Randoms.Randomizer();
// Обрезаем видео с помощью VideoEditor
VideoEditor.trimVideo(name, newName, startInSeconds, endInSeconds);
} catch (IOException ex) {
ex.printStackTrace();
}
});
}
public static void main(String[] args) {
launch();
}
private String formatDuration(Duration duration) {
long minutes = (long) duration.toMinutes();
long seconds = (long) duration.toSeconds() % 60;
long milliseconds = (long) (duration.toMillis() % 1000);
// Форматируем строку в нужный формат: MM:SS:MS
return String.format("%02d:%02d:%03d", minutes, seconds, milliseconds);
}
}
module-info.java
module com.project {
requires javafx.controls;
requires javafx.fxml;
requires javafx.media;
requires org.controlsfx.controls;
requires org.kordamp.bootstrapfx.core;
opens com.project to javafx.fxml;
exports com.project;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>Project</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Project</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.2</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.6</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17.0.6</version> <!-- укажите вашу версию JavaFX, если она отличается -->
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.6</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.2.1</version>
</dependency>
<dependency>
<groupId>org.kordamp.bootstrapfx</groupId>
<artifactId>bootstrapfx-core</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.project/com.project.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
java.io.IOException: Command [light.exe, -nologo, -spdb, -ext, WixUtilExtension, -out, C:UsersvalisAppDataLocalTempjdk.jpackage5771419907643998597imageswin-exe.imageVideoSaver-0.0.1.msi, -sice:ICE27, -loc, C:UsersvalisAppDataLocalTempjdk.jpackage5771419907643998597configMsiInstallerStrings_en.wxl, -cultures:en-us, C:UsersvalisAppDataLocalTempjdk.jpackage5771419907643998597wixobjmain.wixobj, C:UsersvalisAppDataLocalTempjdk.jpackage5771419907643998597wixobjbundle.wixobj, C:UsersvalisAppDataLocalTempjdk.jpackage5771419907643998597wixobjui.wixobj] in C:UsersvalisAppDataLocalTempjdk.jpackage5771419907643998597imageswin-msi.imageVideoSaver exited with 297
Additionally: I just somehow got the application installer working and assembled. (Although I didn’t change absolutely anything). But I noticed an error and had to rebuild the application and again it gives me this error code 👆
I tried different versions of jdk 14, 17 (different versions too). Probably the problem is specifically in my code.
Игорь Арсёнов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
10