-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.java
97 lines (83 loc) · 3.34 KB
/
main.java
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import java.io.File;
import javafx.geometry.Pos;
import main.Convert;
/**
*
* @author Turlu
*/
public class main extends Application {
private static File[] filePaths;
private static File destination;
private static boolean areFilesSet=false;
private static boolean isDestinationSet=false;
@Override
public void start(Stage primaryStage) {
VBox root = new VBox(20);
root.setAlignment(Pos.CENTER);
Button selectDirectory = new Button("Select Your Files");
selectDirectory.setOnAction(e->{
//i want to be able to put a list of files
JFileChooser chose=new JFileChooser();
chose.setMultiSelectionEnabled(true);
chose.setDialogTitle("Choose files to convert to MP3");
chose.setFileSelectionMode(JFileChooser.FILES_ONLY);
int r=chose.showOpenDialog(new JFrame());
if(r == chose.APPROVE_OPTION){
filePaths= chose.getSelectedFiles();
}
});
Button selectDestination = new Button("Select Destination");
selectDestination.setOnAction(e->{
//i want to be able to put a list of files
JFileChooser chose=new JFileChooser();
chose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chose.setDialogTitle("Choose the Destination of the Converted Files");
int r=chose.showOpenDialog(new JFrame());
if(r == chose.APPROVE_OPTION){
destination = chose.getSelectedFile();
}
});
Button convert = new Button("Convert files to MP3");
convert.setOnAction(e->{
for(int i=0;i<filePaths.length;i++){
String[] nameFile = filePaths[i].getAbsolutePath().split("\\\\");
/*for(int j=0;j<nameFile.length;j++)
System.out.println(nameFile[j]);*/
String[] removeExtension = nameFile[nameFile.length-1].split("\\.");
/*for(int j=0;j<removeExtension.length;j++)
System.out.println(removeExtension[j]);*/
File destinationOfficial = new File(destination.getAbsolutePath()+"\\"+removeExtension[0]+".mp3");
System.out.println(destinationOfficial.getAbsolutePath());
Convert.convertMp4ToMp3(filePaths[i], destinationOfficial);
}
System.out.println("DONE!");
});
root.getChildren().addAll(selectDirectory, selectDestination, convert);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("MP4 to MP3");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}