diff --git a/src/main/java/com/zhangmeng/tools/controller/VideoController.java b/src/main/java/com/zhangmeng/tools/controller/VideoController.java index dd7c0d7..d8d1f31 100644 --- a/src/main/java/com/zhangmeng/tools/controller/VideoController.java +++ b/src/main/java/com/zhangmeng/tools/controller/VideoController.java @@ -163,9 +163,6 @@ public class VideoController { @FXML private AnchorPane video_root; - @FXML - private AnchorPane mv_an; - public void full_screen() { AnchorPane root = null; @@ -206,7 +203,9 @@ public class VideoController { public void onChanged(Change c) { while (c.next()) { if (c.wasAdded()) { - VideoController.this.mp = new MediaPlayer((Media) medias.get(VideoController.this.playindex.get())); + if ((medias.size() - 1) >= VideoController.this.playindex.get()) { + VideoController.this.mp = new MediaPlayer(medias.get(VideoController.this.playindex.get())); + } } if (medias.size() == 0) { VideoController.this.isplaying.set(false); @@ -260,11 +259,11 @@ public class VideoController { 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; @@ -312,12 +311,12 @@ public class VideoController { if (event.getClickCount() == 1 && event.getButton() == MouseButton.PRIMARY) { AnchorPane root = null; try { - root = FXMLLoader.load(ResourcesUtils.getResource("music-set")); + root = FXMLLoader.load(ResourcesUtils.getResource("video-set")); } catch (IOException e) { e.printStackTrace(); } - Stage primaryStage= (Stage) VideoController.this.listView.getScene().getWindow(); - AlertUtils.alert("设置",root,primaryStage); + Stage primaryStage = (Stage) VideoController.this.listView.getScene().getWindow(); + AlertUtils.alert("设置", root, primaryStage); } }); } @@ -342,7 +341,7 @@ public class VideoController { }); this.iv_cycle.setOnMouseClicked(event -> { if (event.getButton().equals(MouseButton.PRIMARY)) { - log.info("随机播放按钮:{}","cycle_button"); + log.info("随机播放按钮:{}", "cycle_button"); VideoController.this.cycletype.set((VideoController.this.cycletype.get() + 1) % 3); VideoController.this.iv_cycle.setImage(ICON_WHITE_RANDOM); } @@ -419,7 +418,7 @@ public class VideoController { 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 (VideoController.this.iv_vol.getImage().equals(vol_white)) { VideoController.this.iv_vol.setImage(vol_black); @@ -439,7 +438,7 @@ public class VideoController { } }); this.iv_vol.setOnMouseClicked(event -> { - log.info("音量按钮:{}" , event.getButton().name()); + log.info("音量按钮:{}", event.getButton().name()); if (event.getButton().equals(MouseButton.PRIMARY) && VideoController.this.mp != null) { if (VideoController.this.mp.isMute()) { VideoController.this.mp.setMute(false); @@ -532,7 +531,7 @@ public class VideoController { this.mp.setVolume(sl_vol_num); this.sl_vol.valueProperty().addListener((observableValue, number, t1) -> { - log.info("音量调节:{}",t1.doubleValue()); + log.info("音量调节:{}", t1.doubleValue()); VideoController.this.mp.setVolume(t1.doubleValue() / 100); }); @@ -562,7 +561,7 @@ public class VideoController { this.mv.setMediaPlayer(mp); } - public void initListView(){ + public void initListView() { listView.setItems(files); Text placehold = new Text("列表为空,点击设置添加音乐目录"); placehold.setFill(Color.WHITE); @@ -574,7 +573,7 @@ public class VideoController { 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() { @@ -596,7 +595,7 @@ public class VideoController { this.setAlignment(Pos.CENTER_LEFT); 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(null); this.setOpacity(0.0D); @@ -623,12 +622,12 @@ public class VideoController { 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); } @@ -656,7 +655,7 @@ public class VideoController { }); progressBar.setOnMouseDragged(event1 -> { - if ( player.getStatus() == MediaPlayer.Status.PLAYING) { + if (player.getStatus() == MediaPlayer.Status.PLAYING) { player.seek(progressBar.getCurrentTime()); } }); @@ -670,21 +669,15 @@ public class VideoController { } public static ObservableList getDirsList() { - if (dirs.size() != 0) { - return dirs; - } else { - String dir = config_path(); -// dir = new String(dir.getBytes(), Charset.forName(LRC_CODE)); - dir = "F:\\B站\\JavaFX视频教程\\1到30课"; - 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("video.properties"); InputStream inputStream = resource.getStream(); Properties properties = new Properties(); @@ -733,13 +726,12 @@ public class VideoController { } 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("mp4"); } }); - + files.clear(); for (int i = 0; i < addfiles.length; ++i) { Media media = new Media(addfiles[i].toURI().toASCIIString()); medias.add(media); diff --git a/src/main/java/com/zhangmeng/tools/controller/VideoSetController.java b/src/main/java/com/zhangmeng/tools/controller/VideoSetController.java index 7d6d79d..600395c 100644 --- a/src/main/java/com/zhangmeng/tools/controller/VideoSetController.java +++ b/src/main/java/com/zhangmeng/tools/controller/VideoSetController.java @@ -30,6 +30,8 @@ public class VideoSetController { @FXML private TextField text_file; + private File file; + @FXML public void initialize(){ log.info("music set ...."); @@ -45,12 +47,13 @@ public class VideoSetController { Stage stage = (Stage) file_choose_button.getScene().getWindow(); DirectoryChooser dc = new DirectoryChooser(); dc.setTitle("文件夹选择器"); - File file = dc.showDialog(stage); + file = dc.showDialog(stage); if (file != null){ String path = file.getAbsolutePath(); text_file.setText(path); + }else { + AlertUtils.alert_warning("请选择文件夹!"); } - VideoController.addDir(file); } @FXML @@ -64,6 +67,11 @@ public class VideoSetController { //关闭 Stage stage = (Stage) text_file.getScene().getWindow(); stage.close(); + + if (file != null){ + VideoController.addDir(file); + } + }