2023年5月18日17:05:59 音乐后台播放

master
zhangmeng 2023-05-18 17:06:18 +08:00
parent d0c080e2ad
commit 15d36b504d
3 changed files with 72 additions and 40 deletions

View File

@ -0,0 +1,29 @@
package com.zhangmeng.tools.config;
import javafx.scene.layout.AnchorPane;
import java.util.HashMap;
import java.util.Map;
/**
* @author :
* @version : 1.0
* @date : 2023-05-18 16:22
*/
public class Constants {
public enum Type {
Music
}
public static Map<Type, AnchorPane> pane_map = new HashMap<>();
public static AnchorPane getRoot(Type type) {
return pane_map.get(type);
}
public static AnchorPane setRoot(Type type,AnchorPane root) {
return pane_map.put(type,root);
}
}

View File

@ -585,15 +585,13 @@ public class MusicController {
private void list_cell() {
listView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
private int position;
Text text = null;
public ListCell<File> call(ListView<File> param) {
final ListCell<File> cell = new ListCell<File>() {
protected void updateItem(File item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item != null) {
text = new Text(sb.substring(0, sb.length() - 4));
sb = new StringBuffer(item.getName());
Text text = new Text(sb.substring(0, sb.length() - 4));
text.setWrappingWidth(300.0D);
text.setTextAlignment(TextAlignment.CENTER);
if (this.getIndex() == MusicController.this.playindex.get()) {
@ -615,17 +613,6 @@ public class MusicController {
}
};
cell.hoverProperty().addListener((observableValue, aBoolean, t1) -> {
if (t1 && !text.getText().equals("")) {
position = listView.getItems().indexOf(text.getText());
listView.getFocusModel().focus(position);
cell.setStyle("-fx-background-color: #cbcacb");
} else {
cell.setStyle("-fx-background-color: " + color_cell);
}
});
MenuItem mi1 = new MenuItem("从列表中移除");
mi1.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
@ -644,17 +631,17 @@ public class MusicController {
});
MusicController.this.playindex.addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
Text text;
Text text2;
if (newValue.intValue() == cell.getIndex()) {
if (cell.getGraphic() != null) {
text = (Text) cell.getGraphic();
text.setFont(Font.font(16.0D));
text.setFill(Color.DEEPSKYBLUE);
text2 = (Text) cell.getGraphic();
text2.setFont(Font.font(16.0D));
text2.setFill(Color.DEEPSKYBLUE);
}
} else if (cell.getGraphic() != null) {
text = (Text) cell.getGraphic();
text.setFont(Font.font(13.0D));
text.setFill(Color.BLACK);
text2 = (Text) cell.getGraphic();
text2.setFont(Font.font(13.0D));
text2.setFill(Color.BLACK);
}
}

View File

@ -26,6 +26,7 @@
package com.zhangmeng.tools.controller;
import com.zhangmeng.tools.config.Constants;
import com.zhangmeng.tools.utils.ImagePath;
import com.zhangmeng.tools.utils.ResourcesUtils;
import javafx.beans.property.SimpleDoubleProperty;
@ -89,6 +90,20 @@ public class PlayerController {
public static final String color_cell = "#f4f4f4";
public void close_current_page_init() {
// if (video != null) {
// MediaPlayer mp = videoController.getMp();
// if (mp != null){
// mp.stop();
// }
// }
//
// if (music != null) {
// MediaPlayer mp = musicController.getMp();
// if (mp != null){
// mp.stop();
// }
// }
if (video != null) {
MediaPlayer mp = videoController.getMp();
if (mp != null) {
@ -97,11 +112,9 @@ public class PlayerController {
}
if (music != null) {
MediaPlayer mp = musicController.getMp();
if (mp != null){
mp.stop();
}
Constants.setRoot(Constants.Type.Music,music);
}
}
@FXML
@ -397,8 +410,10 @@ public class PlayerController {
private void music(boolean flag) {
listView.getSelectionModel().select(1);
if (!flag) {
if (Constants.getRoot(Constants.Type.Music) != null){
music = Constants.getRoot(Constants.Type.Music);
}else {
try {
// root = FXMLLoader.load(ResourcesUtils.getResource("music"));
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("music"));
root = load.load();
musicController = load.getController();
@ -406,6 +421,7 @@ public class PlayerController {
e.printStackTrace();
}
music = root;
}
} else {
root = music;
}