2023年5月18日17:05:59 音乐后台播放
parent
d0c080e2ad
commit
15d36b504d
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -585,15 +585,13 @@ public class MusicController {
|
||||||
|
|
||||||
private void list_cell() {
|
private void list_cell() {
|
||||||
listView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
|
listView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
|
||||||
private int position;
|
|
||||||
Text text = null;
|
|
||||||
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>() {
|
||||||
protected void updateItem(File item, boolean empty) {
|
protected void updateItem(File item, boolean empty) {
|
||||||
super.updateItem(item, empty);
|
super.updateItem(item, empty);
|
||||||
if (!empty && item != null) {
|
if (!empty && item != null) {
|
||||||
text = new Text(sb.substring(0, sb.length() - 4));
|
|
||||||
sb = new StringBuffer(item.getName());
|
sb = new StringBuffer(item.getName());
|
||||||
|
Text text = new Text(sb.substring(0, sb.length() - 4));
|
||||||
text.setWrappingWidth(300.0D);
|
text.setWrappingWidth(300.0D);
|
||||||
text.setTextAlignment(TextAlignment.CENTER);
|
text.setTextAlignment(TextAlignment.CENTER);
|
||||||
if (this.getIndex() == MusicController.this.playindex.get()) {
|
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("从列表中移除");
|
MenuItem mi1 = new MenuItem("从列表中移除");
|
||||||
mi1.setOnAction(new EventHandler<ActionEvent>() {
|
mi1.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
|
|
@ -644,17 +631,17 @@ public class MusicController {
|
||||||
});
|
});
|
||||||
MusicController.this.playindex.addListener(new ChangeListener<Number>() {
|
MusicController.this.playindex.addListener(new ChangeListener<Number>() {
|
||||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
|
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
|
||||||
Text text;
|
Text text2;
|
||||||
if (newValue.intValue() == cell.getIndex()) {
|
if (newValue.intValue() == cell.getIndex()) {
|
||||||
if (cell.getGraphic() != null) {
|
if (cell.getGraphic() != null) {
|
||||||
text = (Text) cell.getGraphic();
|
text2 = (Text) cell.getGraphic();
|
||||||
text.setFont(Font.font(16.0D));
|
text2.setFont(Font.font(16.0D));
|
||||||
text.setFill(Color.DEEPSKYBLUE);
|
text2.setFill(Color.DEEPSKYBLUE);
|
||||||
}
|
}
|
||||||
} else if (cell.getGraphic() != null) {
|
} else if (cell.getGraphic() != null) {
|
||||||
text = (Text) cell.getGraphic();
|
text2 = (Text) cell.getGraphic();
|
||||||
text.setFont(Font.font(13.0D));
|
text2.setFont(Font.font(13.0D));
|
||||||
text.setFill(Color.BLACK);
|
text2.setFill(Color.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
package com.zhangmeng.tools.controller;
|
package com.zhangmeng.tools.controller;
|
||||||
|
|
||||||
|
import com.zhangmeng.tools.config.Constants;
|
||||||
import com.zhangmeng.tools.utils.ImagePath;
|
import com.zhangmeng.tools.utils.ImagePath;
|
||||||
import com.zhangmeng.tools.utils.ResourcesUtils;
|
import com.zhangmeng.tools.utils.ResourcesUtils;
|
||||||
import javafx.beans.property.SimpleDoubleProperty;
|
import javafx.beans.property.SimpleDoubleProperty;
|
||||||
|
|
@ -89,6 +90,20 @@ public class PlayerController {
|
||||||
public static final String color_cell = "#f4f4f4";
|
public static final String color_cell = "#f4f4f4";
|
||||||
|
|
||||||
public void close_current_page_init() {
|
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) {
|
if (video != null) {
|
||||||
MediaPlayer mp = videoController.getMp();
|
MediaPlayer mp = videoController.getMp();
|
||||||
if (mp != null) {
|
if (mp != null) {
|
||||||
|
|
@ -97,11 +112,9 @@ public class PlayerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (music != null) {
|
if (music != null) {
|
||||||
MediaPlayer mp = musicController.getMp();
|
Constants.setRoot(Constants.Type.Music,music);
|
||||||
if (mp != null){
|
|
||||||
mp.stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|
@ -397,8 +410,10 @@ public class PlayerController {
|
||||||
private void music(boolean flag) {
|
private void music(boolean flag) {
|
||||||
listView.getSelectionModel().select(1);
|
listView.getSelectionModel().select(1);
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
|
if (Constants.getRoot(Constants.Type.Music) != null){
|
||||||
|
music = Constants.getRoot(Constants.Type.Music);
|
||||||
|
}else {
|
||||||
try {
|
try {
|
||||||
// root = FXMLLoader.load(ResourcesUtils.getResource("music"));
|
|
||||||
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("music"));
|
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("music"));
|
||||||
root = load.load();
|
root = load.load();
|
||||||
musicController = load.getController();
|
musicController = load.getController();
|
||||||
|
|
@ -406,6 +421,7 @@ public class PlayerController {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
music = root;
|
music = root;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
root = music;
|
root = music;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue