完善影音工具单例化 2023年2月18日09:23:12

master
zhangmeng 2023-02-18 09:23:20 +08:00
parent ce74eed863
commit 31905312fc
1 changed files with 82 additions and 42 deletions

View File

@ -29,6 +29,7 @@ import javafx.stage.Stage;
import javafx.util.Callback; import javafx.util.Callback;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.trace.http.TraceableRequest;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -45,14 +46,16 @@ public class PlayerController {
private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0); private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0);
private AnchorPane root; private AnchorPane root;
private AnchorPane video;
private AnchorPane music;
private AnchorPane vip_parser;
@FXML @FXML
private ListView<ResourcesUtils.Player> listView; private ListView<ResourcesUtils.Player> listView;
@FXML @FXML
private SplitPane splitPane; private SplitPane splitPane;
private MediaView view;
public static final String color_cell = "#f4f4f4"; public static final String color_cell = "#f4f4f4";
@FXML @FXML
@ -67,17 +70,29 @@ public class PlayerController {
@FXML @FXML
public void video_menu_item() { public void video_menu_item() {
video(); boolean flag = false;
if (video != null) {
flag = true;
}
video(flag);
} }
@FXML @FXML
public void music_menu_item() { public void music_menu_item() {
music(); boolean flag = false;
if (music != null) {
flag = true;
}
music(flag);
} }
@FXML @FXML
public void vip_parser_menu_item() { public void vip_parser_menu_item() {
vip_parser(); boolean flag = false;
if (vip_parser != null) {
flag = true;
}
vip_parser(flag);
} }
public void load_encrypt() { public void load_encrypt() {
@ -99,25 +114,36 @@ public class PlayerController {
init(); init();
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) { if (newValue != null) {
boolean flag = false;
if (newValue.getIndex() == 0) { if (newValue.getIndex() == 0) {
video(); if (video != null) {
flag = true;
}
video(flag);
} }
if (newValue.getIndex() == 1) { if (newValue.getIndex() == 1) {
music(); if (music != null) {
flag = true;
}
music(flag);
} }
if (newValue.getIndex() == 2) { if (newValue.getIndex() == 2) {
vip_parser(); if (vip_parser != null) {
flag = true;
}
vip_parser(flag);
} }
} }
}); });
} }
public static Image getImage(ResourcesUtils.Player player){ public static Image getImage(ResourcesUtils.Player player) {
return switch (player){ return switch (player) {
case Video -> new Image(ImagePath.path(ImagePath.ImagePathType.VIDEO_PLAYER)); case Video -> new Image(ImagePath.path(ImagePath.ImagePathType.VIDEO_PLAYER));
case Music -> new Image(ImagePath.path(ImagePath.ImagePathType.MUSIC_PLAYER)); case Music -> new Image(ImagePath.path(ImagePath.ImagePathType.MUSIC_PLAYER));
case VipParser -> new Image(ImagePath.path(ImagePath.ImagePathType.VIP_PLAYER)); case VipParser -> new Image(ImagePath.path(ImagePath.ImagePathType.VIP_PLAYER));
}; };
} }
public void init() { public void init() {
@ -164,7 +190,7 @@ public class PlayerController {
label.setFont(new Font(16)); label.setFont(new Font(16));
playerListView.getFocusModel().focus(position); playerListView.getFocusModel().focus(position);
listCell.setStyle("-fx-background-color: #f6edc3"); listCell.setStyle("-fx-background-color: #f6edc3");
}else { } else {
label.setPrefHeight(20); label.setPrefHeight(20);
label.setFont(new Font(13)); label.setFont(new Font(13));
listCell.setStyle("-fx-background-color: " + color_cell); listCell.setStyle("-fx-background-color: " + color_cell);
@ -175,25 +201,53 @@ public class PlayerController {
return listCell; return listCell;
} }
}); });
video(); video(false);
} }
private void music() { private void music(boolean flag) {
listView.getSelectionModel().select(1); listView.getSelectionModel().select(1);
try { if (!flag) {
root = FXMLLoader.load(ResourcesUtils.getResource("music")); try {
} catch (IOException e) { root = FXMLLoader.load(ResourcesUtils.getResource("music"));
e.printStackTrace(); } catch (IOException e) {
e.printStackTrace();
}
music = root;
} else {
root = music;
} }
common_method(); common_method();
} }
private void vip_parser() { private void vip_parser(boolean flag) {
listView.getSelectionModel().select(2); listView.getSelectionModel().select(2);
try {
root = FXMLLoader.load(ResourcesUtils.getResource("vip-parser")); if (!flag) {
} catch (IOException e) { try {
e.printStackTrace(); root = FXMLLoader.load(ResourcesUtils.getResource("vip-parser"));
} catch (IOException e) {
e.printStackTrace();
}
vip_parser = root;
} else {
root = vip_parser;
}
common_method();
}
private void video(boolean flag) {
//默认选择第一个
listView.getSelectionModel().select(0);
if (!flag) {
try {
root = FXMLLoader.load(ResourcesUtils.getResource("video"));
} catch (IOException e) {
e.printStackTrace();
}
video = root;
} else {
root = video;
} }
common_method(); common_method();
} }
@ -215,29 +269,15 @@ public class PlayerController {
log.info("player:--->height:{}", height); log.info("player:--->height:{}", height);
} }
}); });
view = (MediaView)root.lookup("#mv");
view.fitHeightProperty().bind(root.heightProperty());
view.fitWidthProperty().bind(root.widthProperty());
this.width.addListener((observable, oldValue, newValue) -> { this.width.addListener((observable, oldValue, newValue) -> {
PlayerController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth()); PlayerController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth());
log.info("newValue.doubleValue():{}",newValue.doubleValue()); log.info("newValue.doubleValue():{}", newValue.doubleValue());
}); });
this.height.addListener((observable, oldValue, newValue) -> { this.height.addListener((observable, oldValue, newValue) -> {
PlayerController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight()); PlayerController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight());
log.info("newValue.doubleValue():{}" ,newValue.doubleValue()); log.info("newValue.doubleValue():{}", newValue.doubleValue());
}); });
} }
private void video() {
//默认选择第一个
listView.getSelectionModel().select(0);
try {
root = FXMLLoader.load(ResourcesUtils.getResource("video"));
} catch (IOException e) {
e.printStackTrace();
}
common_method();
}
} }