修改 音乐视频路径设置 2023年2月21日15:34:46
parent
b3a6276236
commit
000d7de773
|
|
@ -64,8 +64,6 @@ public class MusicController {
|
||||||
private static ObservableList<File> dirs = FXCollections.observableArrayList();
|
private static ObservableList<File> dirs = FXCollections.observableArrayList();
|
||||||
private static ObservableList<Media> medias = FXCollections.observableArrayList();
|
private static ObservableList<Media> medias = FXCollections.observableArrayList();
|
||||||
private static ObservableList<File> files = FXCollections.observableArrayList();
|
private static ObservableList<File> files = FXCollections.observableArrayList();
|
||||||
private static String abpath = System.getProperty("user.dir") + "/";
|
|
||||||
private static BufferedWriter bw = null;
|
|
||||||
public ScrollPane scrollPane;
|
public ScrollPane scrollPane;
|
||||||
private MediaPlayer mp;
|
private MediaPlayer mp;
|
||||||
private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false);
|
private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false);
|
||||||
|
|
@ -161,8 +159,6 @@ public class MusicController {
|
||||||
@FXML
|
@FXML
|
||||||
private RXMediaProgressBar progressBar;
|
private RXMediaProgressBar progressBar;
|
||||||
|
|
||||||
private final String LRC_CODE = "gbk";
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
files = getMusicFiles();
|
files = getMusicFiles();
|
||||||
|
|
@ -225,11 +221,11 @@ public class MusicController {
|
||||||
initSt();
|
initSt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initSt(){
|
public void initSt() {
|
||||||
this.hbox = new HBox(gap);
|
this.hbox = new HBox(gap);
|
||||||
this.hbox.setScaleY(-1.0D);
|
this.hbox.setScaleY(-1.0D);
|
||||||
this.height = FXCollections.observableArrayList();
|
this.height = FXCollections.observableArrayList();
|
||||||
for(int i = 0; i < this.number; ++i) {
|
for (int i = 0; i < this.number; ++i) {
|
||||||
this.height.add(new SimpleFloatProperty(0.0F));
|
this.height.add(new SimpleFloatProperty(0.0F));
|
||||||
Color color = ColorUtils.random_color();
|
Color color = ColorUtils.random_color();
|
||||||
// Color color = Color.DEEPSKYBLUE;
|
// Color color = Color.DEEPSKYBLUE;
|
||||||
|
|
@ -281,8 +277,8 @@ public class MusicController {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Stage primaryStage= (Stage) MusicController.this.listView.getScene().getWindow();
|
Stage primaryStage = (Stage) MusicController.this.listView.getScene().getWindow();
|
||||||
AlertUtils.alert("设置",root,primaryStage);
|
AlertUtils.alert("设置", root, primaryStage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -307,7 +303,7 @@ public class MusicController {
|
||||||
});
|
});
|
||||||
this.iv_cycle.setOnMouseClicked(event -> {
|
this.iv_cycle.setOnMouseClicked(event -> {
|
||||||
if (event.getButton().equals(MouseButton.PRIMARY)) {
|
if (event.getButton().equals(MouseButton.PRIMARY)) {
|
||||||
log.info("随机播放按钮:{}","cycle_button");
|
log.info("随机播放按钮:{}", "cycle_button");
|
||||||
MusicController.this.cycletype.set((MusicController.this.cycletype.get() + 1) % 3);
|
MusicController.this.cycletype.set((MusicController.this.cycletype.get() + 1) % 3);
|
||||||
MusicController.this.iv_cycle.setImage(ICON_WHITE_RANDOM);
|
MusicController.this.iv_cycle.setImage(ICON_WHITE_RANDOM);
|
||||||
}
|
}
|
||||||
|
|
@ -384,7 +380,7 @@ public class MusicController {
|
||||||
|
|
||||||
this.iv_vol.hoverProperty().addListener(new ChangeListener<Boolean>() {
|
this.iv_vol.hoverProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||||
log.info("静音按钮:{}" , newValue);
|
log.info("静音按钮:{}", newValue);
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
if (MusicController.this.iv_vol.getImage().equals(vol_white)) {
|
if (MusicController.this.iv_vol.getImage().equals(vol_white)) {
|
||||||
MusicController.this.iv_vol.setImage(vol_black);
|
MusicController.this.iv_vol.setImage(vol_black);
|
||||||
|
|
@ -404,7 +400,7 @@ public class MusicController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.iv_vol.setOnMouseClicked(event -> {
|
this.iv_vol.setOnMouseClicked(event -> {
|
||||||
log.info("音量按钮:{}" , event.getButton().name());
|
log.info("音量按钮:{}", event.getButton().name());
|
||||||
if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) {
|
if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) {
|
||||||
if (MusicController.this.mp.isMute()) {
|
if (MusicController.this.mp.isMute()) {
|
||||||
MusicController.this.mp.setMute(false);
|
MusicController.this.mp.setMute(false);
|
||||||
|
|
@ -498,7 +494,7 @@ public class MusicController {
|
||||||
this.mp.setVolume(sl_vol_num);
|
this.mp.setVolume(sl_vol_num);
|
||||||
|
|
||||||
this.sl_vol.valueProperty().addListener((observableValue, number, t1) -> {
|
this.sl_vol.valueProperty().addListener((observableValue, number, t1) -> {
|
||||||
log.info("音量调节:{}",t1.doubleValue());
|
log.info("音量调节:{}", t1.doubleValue());
|
||||||
MusicController.this.mp.setVolume(t1.doubleValue() / 100);
|
MusicController.this.mp.setVolume(t1.doubleValue() / 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -528,7 +524,7 @@ public class MusicController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initListView(){
|
public void initListView() {
|
||||||
listView.setItems(files);
|
listView.setItems(files);
|
||||||
Text placehold = new Text("列表为空,点击设置添加音乐目录");
|
Text placehold = new Text("列表为空,点击设置添加音乐目录");
|
||||||
placehold.setFill(Color.WHITE);
|
placehold.setFill(Color.WHITE);
|
||||||
|
|
@ -540,7 +536,7 @@ public class MusicController {
|
||||||
list_cell();
|
list_cell();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void list_cell(){
|
private void list_cell() {
|
||||||
listView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
|
listView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
|
||||||
public ListCell<File> call(ListView<File> param) {
|
public ListCell<File> call(ListView<File> param) {
|
||||||
final ListCell<File> cell = new ListCell<File>() {
|
final ListCell<File> cell = new ListCell<File>() {
|
||||||
|
|
@ -562,9 +558,9 @@ public class MusicController {
|
||||||
this.setAlignment(Pos.CENTER);
|
this.setAlignment(Pos.CENTER);
|
||||||
this.setGraphic(text);
|
this.setGraphic(text);
|
||||||
this.setOpacity(1.0D);
|
this.setOpacity(1.0D);
|
||||||
this.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, (CornerRadii)null, (Insets)null)));
|
this.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, (CornerRadii) null, (Insets) null)));
|
||||||
} else {
|
} else {
|
||||||
this.setGraphic((Node)null);
|
this.setGraphic((Node) null);
|
||||||
this.setOpacity(0.0D);
|
this.setOpacity(0.0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -591,12 +587,12 @@ public class MusicController {
|
||||||
Text text;
|
Text text;
|
||||||
if (newValue.intValue() == cell.getIndex()) {
|
if (newValue.intValue() == cell.getIndex()) {
|
||||||
if (cell.getGraphic() != null) {
|
if (cell.getGraphic() != null) {
|
||||||
text = (Text)cell.getGraphic();
|
text = (Text) cell.getGraphic();
|
||||||
text.setFont(Font.font(16.0D));
|
text.setFont(Font.font(16.0D));
|
||||||
text.setFill(Color.DEEPSKYBLUE);
|
text.setFill(Color.DEEPSKYBLUE);
|
||||||
}
|
}
|
||||||
} else if (cell.getGraphic() != null) {
|
} else if (cell.getGraphic() != null) {
|
||||||
text = (Text)cell.getGraphic();
|
text = (Text) cell.getGraphic();
|
||||||
text.setFont(Font.font(13.0D));
|
text.setFont(Font.font(13.0D));
|
||||||
text.setFill(Color.BLACK);
|
text.setFill(Color.BLACK);
|
||||||
}
|
}
|
||||||
|
|
@ -617,7 +613,7 @@ public class MusicController {
|
||||||
});
|
});
|
||||||
|
|
||||||
progressBar.setOnMouseDragged(event1 -> {
|
progressBar.setOnMouseDragged(event1 -> {
|
||||||
if ( player.getStatus() == MediaPlayer.Status.PLAYING) {
|
if (player.getStatus() == MediaPlayer.Status.PLAYING) {
|
||||||
player.seek(progressBar.getCurrentTime());
|
player.seek(progressBar.getCurrentTime());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -658,9 +654,6 @@ public class MusicController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObservableList<File> getDirsList() {
|
public static ObservableList<File> getDirsList() {
|
||||||
if (dirs.size() != 0) {
|
|
||||||
return dirs;
|
|
||||||
} else {
|
|
||||||
String dir = config_path();
|
String dir = config_path();
|
||||||
File file = new File(dir);
|
File file = new File(dir);
|
||||||
if (file.exists() && file.isDirectory()) {
|
if (file.exists() && file.isDirectory()) {
|
||||||
|
|
@ -668,9 +661,8 @@ public class MusicController {
|
||||||
}
|
}
|
||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static String config_path(){
|
public static String config_path() {
|
||||||
Resource resource = new ClassPathResource("music.properties");
|
Resource resource = new ClassPathResource("music.properties");
|
||||||
InputStream inputStream = resource.getStream();
|
InputStream inputStream = resource.getStream();
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
@ -723,71 +715,12 @@ public class MusicController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addDir(File file) {
|
public static void addDir(File file) {
|
||||||
dirs.add(file);
|
File[] addfiles = file.listFiles((dir, name) -> name.endsWith("mp3"));
|
||||||
File[] addfiles = file.listFiles(new FilenameFilter() {
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith("mp3");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (int i = 0; i < addfiles.length; ++i) {
|
for (int i = 0; i < addfiles.length; ++i) {
|
||||||
Media media = new Media(addfiles[i].toURI().toASCIIString());
|
Media media = new Media(addfiles[i].toURI().toASCIIString());
|
||||||
medias.add(media);
|
medias.add(media);
|
||||||
files.add(addfiles[i]);
|
files.add(addfiles[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteDir(File file) {
|
|
||||||
dirs.remove(file);
|
|
||||||
File[] subfiles = file.listFiles(new FilenameFilter() {
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith("mp3");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (int i = 0; i < subfiles.length; ++i) {
|
|
||||||
if (files.contains(subfiles[i])) {
|
|
||||||
int index = files.indexOf(subfiles[i]);
|
|
||||||
medias.remove(index);
|
|
||||||
files.remove(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void refreshPath() {
|
|
||||||
File pathtxt = new File(abpath + "path.txt");
|
|
||||||
if (!pathtxt.exists()) {
|
|
||||||
try {
|
|
||||||
pathtxt.createNewFile();
|
|
||||||
} catch (IOException var4) {
|
|
||||||
var4.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
bw = new BufferedWriter(new FileWriter(pathtxt));
|
|
||||||
} catch (IOException var3) {
|
|
||||||
var3.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
dirs.forEach((t) -> {
|
|
||||||
try {
|
|
||||||
String s = t.getAbsolutePath();
|
|
||||||
bw.write(s + "\r\n");
|
|
||||||
} catch (IOException var2) {
|
|
||||||
var2.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException var2) {
|
|
||||||
var2.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,6 @@ public class VideoController {
|
||||||
private static ObservableList<File> dirs = FXCollections.observableArrayList();
|
private static ObservableList<File> dirs = FXCollections.observableArrayList();
|
||||||
private static ObservableList<Media> medias = FXCollections.observableArrayList();
|
private static ObservableList<Media> medias = FXCollections.observableArrayList();
|
||||||
private static ObservableList<File> files = FXCollections.observableArrayList();
|
private static ObservableList<File> files = FXCollections.observableArrayList();
|
||||||
private static String abpath = System.getProperty("user.dir") + "/";
|
|
||||||
private static BufferedWriter bw = null;
|
|
||||||
private MediaPlayer mp;
|
private MediaPlayer mp;
|
||||||
private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false);
|
private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false);
|
||||||
private final SimpleIntegerProperty playindex = new SimpleIntegerProperty(1);
|
private final SimpleIntegerProperty playindex = new SimpleIntegerProperty(1);
|
||||||
|
|
@ -713,11 +711,7 @@ public class VideoController {
|
||||||
if (files.size() == 0) {
|
if (files.size() == 0) {
|
||||||
getDirsList().forEach((dir) -> {
|
getDirsList().forEach((dir) -> {
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
File[] mfiles = dir.listFiles(new FilenameFilter() {
|
File[] mfiles = dir.listFiles((dir1, name) -> name.endsWith("mp4"));
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith("mp4");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
files.addAll(mfiles);
|
files.addAll(mfiles);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -728,11 +722,7 @@ public class VideoController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addDir(File file) {
|
public static void addDir(File file) {
|
||||||
File[] addfiles = file.listFiles(new FilenameFilter() {
|
File[] addfiles = file.listFiles((dir, name) -> name.endsWith("mp4"));
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith("mp4");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
files.clear();
|
files.clear();
|
||||||
for (int i = 0; i < addfiles.length; ++i) {
|
for (int i = 0; i < addfiles.length; ++i) {
|
||||||
Media media = new Media(addfiles[i].toURI().toASCIIString());
|
Media media = new Media(addfiles[i].toURI().toASCIIString());
|
||||||
|
|
@ -740,21 +730,4 @@ public class VideoController {
|
||||||
files.add(addfiles[i]);
|
files.add(addfiles[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteDir(File file) {
|
|
||||||
dirs.remove(file);
|
|
||||||
File[] subfiles = file.listFiles(new FilenameFilter() {
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith("mp3");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (int i = 0; i < subfiles.length; ++i) {
|
|
||||||
if (files.contains(subfiles[i])) {
|
|
||||||
int index = files.indexOf(subfiles[i]);
|
|
||||||
medias.remove(index);
|
|
||||||
files.remove(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue