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() {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,19 +90,31 @@ 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){
|
||||
mp.stop();
|
||||
if (mp != null) {
|
||||
mp.stop();
|
||||
}
|
||||
}
|
||||
|
||||
if (music != null) {
|
||||
MediaPlayer mp = musicController.getMp();
|
||||
if (mp != null){
|
||||
mp.stop();
|
||||
}
|
||||
Constants.setRoot(Constants.Type.Music,music);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
|
@ -275,7 +288,7 @@ public class PlayerController {
|
|||
}
|
||||
|
||||
|
||||
public void load_encrypt(int index ) {
|
||||
public void load_encrypt(int index) {
|
||||
close_current_page_init();
|
||||
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||
AnchorPane fx = null;
|
||||
|
|
@ -397,15 +410,18 @@ public class PlayerController {
|
|||
private void music(boolean flag) {
|
||||
listView.getSelectionModel().select(1);
|
||||
if (!flag) {
|
||||
try {
|
||||
// root = FXMLLoader.load(ResourcesUtils.getResource("music"));
|
||||
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("music"));
|
||||
root = load.load();
|
||||
musicController = load.getController();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
if (Constants.getRoot(Constants.Type.Music) != null){
|
||||
music = Constants.getRoot(Constants.Type.Music);
|
||||
}else {
|
||||
try {
|
||||
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("music"));
|
||||
root = load.load();
|
||||
musicController = load.getController();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
music = root;
|
||||
}
|
||||
music = root;
|
||||
} else {
|
||||
root = music;
|
||||
}
|
||||
|
|
@ -451,9 +467,9 @@ public class PlayerController {
|
|||
if (!flag) {
|
||||
try {
|
||||
// root = FXMLLoader.load(ResourcesUtils.getResource("video"));
|
||||
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("video"));
|
||||
root = load.load();
|
||||
videoController = load.getController();
|
||||
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("video"));
|
||||
root = load.load();
|
||||
videoController = load.getController();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -589,7 +605,7 @@ public class PlayerController {
|
|||
|
||||
public void music_parser_menu_item(ActionEvent event) {
|
||||
boolean flag = false;
|
||||
if (music_parser != null){
|
||||
if (music_parser != null) {
|
||||
flag = true;
|
||||
}
|
||||
music_parser(flag);
|
||||
|
|
|
|||
Loading…
Reference in New Issue