完善影音工具单例化 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,14 +114,25 @@ 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);
} }
} }
}); });
@ -175,26 +201,54 @@ 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);
if (!flag) {
try { try {
root = FXMLLoader.load(ResourcesUtils.getResource("music")); root = FXMLLoader.load(ResourcesUtils.getResource("music"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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);
if (!flag) {
try { try {
root = FXMLLoader.load(ResourcesUtils.getResource("vip-parser")); root = FXMLLoader.load(ResourcesUtils.getResource("vip-parser"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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,9 +269,6 @@ 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());
@ -229,15 +280,4 @@ public class PlayerController {
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();
}
} }