diff --git a/src/main/java/com/zhangmeng/tools/controller/MusicController.java b/src/main/java/com/zhangmeng/tools/controller/MusicController.java index d9ed34a..e0fbbdf 100644 --- a/src/main/java/com/zhangmeng/tools/controller/MusicController.java +++ b/src/main/java/com/zhangmeng/tools/controller/MusicController.java @@ -64,8 +64,6 @@ public class MusicController { private static ObservableList dirs = FXCollections.observableArrayList(); private static ObservableList medias = FXCollections.observableArrayList(); private static ObservableList files = FXCollections.observableArrayList(); - private static String abpath = System.getProperty("user.dir") + "/"; - private static BufferedWriter bw = null; public ScrollPane scrollPane; private MediaPlayer mp; private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false); @@ -161,8 +159,6 @@ public class MusicController { @FXML private RXMediaProgressBar progressBar; - private final String LRC_CODE = "gbk"; - @FXML public void initialize() { files = getMusicFiles(); @@ -225,11 +221,11 @@ public class MusicController { initSt(); } - public void initSt(){ + public void initSt() { this.hbox = new HBox(gap); this.hbox.setScaleY(-1.0D); 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)); Color color = ColorUtils.random_color(); // Color color = Color.DEEPSKYBLUE; @@ -281,8 +277,8 @@ public class MusicController { } catch (IOException e) { e.printStackTrace(); } - Stage primaryStage= (Stage) MusicController.this.listView.getScene().getWindow(); - AlertUtils.alert("设置",root,primaryStage); + Stage primaryStage = (Stage) MusicController.this.listView.getScene().getWindow(); + AlertUtils.alert("设置", root, primaryStage); } }); } @@ -307,7 +303,7 @@ public class MusicController { }); this.iv_cycle.setOnMouseClicked(event -> { 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.iv_cycle.setImage(ICON_WHITE_RANDOM); } @@ -384,7 +380,7 @@ public class MusicController { this.iv_vol.hoverProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { - log.info("静音按钮:{}" , newValue); + log.info("静音按钮:{}", newValue); if (newValue) { if (MusicController.this.iv_vol.getImage().equals(vol_white)) { MusicController.this.iv_vol.setImage(vol_black); @@ -404,7 +400,7 @@ public class MusicController { } }); 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 (MusicController.this.mp.isMute()) { MusicController.this.mp.setMute(false); @@ -498,7 +494,7 @@ public class MusicController { this.mp.setVolume(sl_vol_num); this.sl_vol.valueProperty().addListener((observableValue, number, t1) -> { - log.info("音量调节:{}",t1.doubleValue()); + log.info("音量调节:{}", t1.doubleValue()); MusicController.this.mp.setVolume(t1.doubleValue() / 100); }); @@ -528,7 +524,7 @@ public class MusicController { } - public void initListView(){ + public void initListView() { listView.setItems(files); Text placehold = new Text("列表为空,点击设置添加音乐目录"); placehold.setFill(Color.WHITE); @@ -540,7 +536,7 @@ public class MusicController { list_cell(); } - private void list_cell(){ + private void list_cell() { listView.setCellFactory(new Callback, ListCell>() { public ListCell call(ListView param) { final ListCell cell = new ListCell() { @@ -562,9 +558,9 @@ public class MusicController { this.setAlignment(Pos.CENTER); this.setGraphic(text); 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 { - this.setGraphic((Node)null); + this.setGraphic((Node) null); this.setOpacity(0.0D); } @@ -591,12 +587,12 @@ public class MusicController { Text text; if (newValue.intValue() == cell.getIndex()) { if (cell.getGraphic() != null) { - text = (Text)cell.getGraphic(); + text = (Text) cell.getGraphic(); text.setFont(Font.font(16.0D)); text.setFill(Color.DEEPSKYBLUE); } } else if (cell.getGraphic() != null) { - text = (Text)cell.getGraphic(); + text = (Text) cell.getGraphic(); text.setFont(Font.font(13.0D)); text.setFill(Color.BLACK); } @@ -617,7 +613,7 @@ public class MusicController { }); progressBar.setOnMouseDragged(event1 -> { - if ( player.getStatus() == MediaPlayer.Status.PLAYING) { + if (player.getStatus() == MediaPlayer.Status.PLAYING) { player.seek(progressBar.getCurrentTime()); } }); @@ -658,19 +654,15 @@ public class MusicController { } public static ObservableList getDirsList() { - if (dirs.size() != 0) { - return dirs; - } else { - String dir = config_path(); - File file = new File(dir); - if (file.exists() && file.isDirectory()) { - dirs.add(file); - } - return dirs; + String dir = config_path(); + File file = new File(dir); + if (file.exists() && file.isDirectory()) { + dirs.add(file); } + return dirs; } - public static String config_path(){ + public static String config_path() { Resource resource = new ClassPathResource("music.properties"); InputStream inputStream = resource.getStream(); Properties properties = new Properties(); @@ -723,71 +715,12 @@ public class MusicController { } public static void addDir(File file) { - dirs.add(file); - File[] addfiles = file.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith("mp3"); - } - }); + File[] addfiles = file.listFiles((dir, name) -> name.endsWith("mp3")); for (int i = 0; i < addfiles.length; ++i) { Media media = new Media(addfiles[i].toURI().toASCIIString()); medias.add(media); 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(); - } } } diff --git a/src/main/java/com/zhangmeng/tools/controller/VideoController.java b/src/main/java/com/zhangmeng/tools/controller/VideoController.java index e5144ec..074a0eb 100644 --- a/src/main/java/com/zhangmeng/tools/controller/VideoController.java +++ b/src/main/java/com/zhangmeng/tools/controller/VideoController.java @@ -61,8 +61,6 @@ public class VideoController { private static ObservableList dirs = FXCollections.observableArrayList(); private static ObservableList medias = FXCollections.observableArrayList(); private static ObservableList files = FXCollections.observableArrayList(); - private static String abpath = System.getProperty("user.dir") + "/"; - private static BufferedWriter bw = null; private MediaPlayer mp; private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false); private final SimpleIntegerProperty playindex = new SimpleIntegerProperty(1); @@ -713,11 +711,7 @@ public class VideoController { if (files.size() == 0) { getDirsList().forEach((dir) -> { if (dir.exists()) { - File[] mfiles = dir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith("mp4"); - } - }); + File[] mfiles = dir.listFiles((dir1, name) -> name.endsWith("mp4")); files.addAll(mfiles); } }); @@ -728,11 +722,7 @@ public class VideoController { } public static void addDir(File file) { - File[] addfiles = file.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith("mp4"); - } - }); + File[] addfiles = file.listFiles((dir, name) -> name.endsWith("mp4")); files.clear(); for (int i = 0; i < addfiles.length; ++i) { Media media = new Media(addfiles[i].toURI().toASCIIString()); @@ -740,21 +730,4 @@ public class VideoController { 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); - } - } - } }