修改切换菜单 音乐 视频 播放 无法暂停的原因

master
zhangmeng 2023-04-20 17:16:10 +08:00
parent 1a264d9864
commit 471ba02b33
4 changed files with 67 additions and 24 deletions

View File

@ -90,6 +90,11 @@ public class MusicController {
private static ObservableList<Media> medias = FXCollections.observableArrayList(); private static ObservableList<Media> medias = FXCollections.observableArrayList();
private static ObservableList<File> files = FXCollections.observableArrayList(); private static ObservableList<File> files = FXCollections.observableArrayList();
public ScrollPane scrollPane; public ScrollPane scrollPane;
public MediaPlayer getMp() {
return mp;
}
private MediaPlayer mp; private MediaPlayer mp;
private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false); private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false);
private final SimpleIntegerProperty playindex = new SimpleIntegerProperty(1); private final SimpleIntegerProperty playindex = new SimpleIntegerProperty(1);

View File

@ -48,6 +48,8 @@ import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Paint; import javafx.scene.paint.Paint;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -73,6 +75,9 @@ public class PlayerController {
private AnchorPane music; private AnchorPane music;
private AnchorPane vip_parser; private AnchorPane vip_parser;
private MusicController musicController;
private VideoController videoController;
@FXML @FXML
private ListView<ResourcesUtils.Player> listView; private ListView<ResourcesUtils.Player> listView;
@ -81,6 +86,22 @@ public class PlayerController {
public static final String color_cell = "#f4f4f4"; 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();
}
}
}
@FXML @FXML
public void md5_menu_item() { public void md5_menu_item() {
load_encrypt(); load_encrypt();
@ -92,51 +113,52 @@ public class PlayerController {
} }
@FXML @FXML
private void hex_16_menu_item(){ private void hex_16_menu_item() {
load_small_tools(0); load_small_tools(0);
} }
@FXML @FXML
private void unicode_menu_item(){ private void unicode_menu_item() {
load_small_tools(1); load_small_tools(1);
} }
@FXML @FXML
private void jwt_menu_item(){ private void jwt_menu_item() {
load_small_tools(2); load_small_tools(2);
} }
@FXML @FXML
private void color_choose_menu_item(){ private void color_choose_menu_item() {
load_small_tools(3); load_small_tools(3);
} }
@FXML @FXML
private void qr_code_menu_item(){ private void qr_code_menu_item() {
load_small_tools(4); load_small_tools(4);
} }
@FXML @FXML
private void base_62_menu_item(){ private void base_62_menu_item() {
load_codec_tools(0); load_codec_tools(0);
} }
@FXML @FXML
private void base_64_menu_item(){ private void base_64_menu_item() {
load_codec_tools(1); load_codec_tools(1);
} }
@FXML @FXML
private void base_32_menu_item(){ private void base_32_menu_item() {
load_codec_tools(2); load_codec_tools(2);
} }
@FXML @FXML
private void morse_coder_menu_item(){ private void morse_coder_menu_item() {
load_codec_tools(3); load_codec_tools(3);
} }
@FXML @FXML
public void sql_code_gen_menu_item(){ public void sql_code_gen_menu_item() {
load_sql_tools(0); load_sql_tools(0);
} }
@ -168,21 +190,22 @@ public class PlayerController {
} }
@FXML @FXML
public void date_query_menu_item(){ public void date_query_menu_item() {
load_small_tools(5); load_small_tools(5);
} }
@FXML @FXML
public void cron_menu_item(){ public void cron_menu_item() {
load_small_tools(6); load_small_tools(6);
} }
@FXML @FXML
public void netty_client_menu_item(){ public void netty_client_menu_item() {
load_network_tools(6); load_network_tools(6);
} }
public void load_network_tools(int index){ public void load_network_tools(int index) {
close_current_page_init();
AnchorPane fx = null; AnchorPane fx = null;
try { try {
fx = FXMLLoader.load(ResourcesUtils.getResource("network-tools")); fx = FXMLLoader.load(ResourcesUtils.getResource("network-tools"));
@ -198,7 +221,8 @@ public class PlayerController {
listView.getSelectionModel().select(index); listView.getSelectionModel().select(index);
} }
public void load_codec_tools(int index){ public void load_codec_tools(int index) {
close_current_page_init();
AnchorPane fx = null; AnchorPane fx = null;
try { try {
fx = FXMLLoader.load(ResourcesUtils.getResource("codec-tools")); fx = FXMLLoader.load(ResourcesUtils.getResource("codec-tools"));
@ -214,7 +238,8 @@ public class PlayerController {
listView.getSelectionModel().select(index); listView.getSelectionModel().select(index);
} }
public void load_sql_tools(int index){ public void load_sql_tools(int index) {
close_current_page_init();
AnchorPane fx = null; AnchorPane fx = null;
try { try {
fx = FXMLLoader.load(ResourcesUtils.getResource("sql-tools")); fx = FXMLLoader.load(ResourcesUtils.getResource("sql-tools"));
@ -230,7 +255,8 @@ public class PlayerController {
listView.getSelectionModel().select(index); listView.getSelectionModel().select(index);
} }
public void load_small_tools(int index){ public void load_small_tools(int index) {
close_current_page_init();
AnchorPane fx = null; AnchorPane fx = null;
try { try {
fx = FXMLLoader.load(ResourcesUtils.getResource("small-tools")); fx = FXMLLoader.load(ResourcesUtils.getResource("small-tools"));
@ -248,9 +274,8 @@ public class PlayerController {
public void load_encrypt() { public void load_encrypt() {
close_current_page_init();
Stage stage = (Stage) splitPane.getScene().getWindow(); Stage stage = (Stage) splitPane.getScene().getWindow();
AnchorPane fx = null; AnchorPane fx = null;
try { try {
fx = FXMLLoader.load(ResourcesUtils.getResource("home")); fx = FXMLLoader.load(ResourcesUtils.getResource("home"));
@ -360,7 +385,10 @@ public class PlayerController {
listView.getSelectionModel().select(1); listView.getSelectionModel().select(1);
if (!flag) { if (!flag) {
try { try {
root = FXMLLoader.load(ResourcesUtils.getResource("music")); // root = FXMLLoader.load(ResourcesUtils.getResource("music"));
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("music"));
root = load.load();
musicController = load.getController();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -393,7 +421,10 @@ public class PlayerController {
if (!flag) { if (!flag) {
try { try {
root = FXMLLoader.load(ResourcesUtils.getResource("video")); // root = FXMLLoader.load(ResourcesUtils.getResource("video"));
FXMLLoader load = new FXMLLoader(ResourcesUtils.getResource("video"));
root = load.load();
videoController = load.getController();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -450,7 +481,8 @@ public class PlayerController {
load_http_tools(2); load_http_tools(2);
} }
public void load_http_tools(int index){ public void load_http_tools(int index) {
close_current_page_init();
AnchorPane fx = null; AnchorPane fx = null;
try { try {
fx = FXMLLoader.load(ResourcesUtils.getResource("http-tools")); fx = FXMLLoader.load(ResourcesUtils.getResource("http-tools"));
@ -481,7 +513,8 @@ public class PlayerController {
load_server_tools(2); load_server_tools(2);
} }
public void load_server_tools(int index){ public void load_server_tools(int index) {
close_current_page_init();
AnchorPane fx = null; AnchorPane fx = null;
try { try {
fx = FXMLLoader.load(ResourcesUtils.getResource("server-tools")); fx = FXMLLoader.load(ResourcesUtils.getResource("server-tools"));

View File

@ -87,6 +87,11 @@ public class VideoController {
private static ObservableList<Media> medias = FXCollections.observableArrayList(); private static ObservableList<Media> medias = FXCollections.observableArrayList();
private static ObservableList<File> files = FXCollections.observableArrayList(); private static ObservableList<File> files = FXCollections.observableArrayList();
private MediaPlayer mp; private MediaPlayer mp;
public MediaPlayer getMp() {
return mp;
}
private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false); private final SimpleBooleanProperty isplaying = new SimpleBooleanProperty(false);
private final SimpleIntegerProperty playindex = new SimpleIntegerProperty(1); private final SimpleIntegerProperty playindex = new SimpleIntegerProperty(1);
private final SimpleDoubleProperty playprogress = new SimpleDoubleProperty(0.0D); private final SimpleDoubleProperty playprogress = new SimpleDoubleProperty(0.0D);

View File

@ -16,7 +16,7 @@
<HBox fx:id="mv_hbox" layoutX="2.0" layoutY="31.0" prefHeight="521.0" prefWidth="1198.0" style="-fx-border-color: #85c486" AnchorPane.bottomAnchor="98.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="0.0"> <HBox fx:id="mv_hbox" layoutX="2.0" layoutY="31.0" prefHeight="521.0" prefWidth="1198.0" style="-fx-border-color: #85c486" AnchorPane.bottomAnchor="98.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="0.0">
<children> <children>
<ListView fx:id="listView" prefHeight="551.0" prefWidth="300.0" /> <ListView fx:id="listView" prefHeight="551.0" prefWidth="300.0" />
<MediaView fx:id="mv" style="-fx-border-color: red;-fx-background-color: #e9df47" HBox.hgrow="ALWAYS"> <MediaView id="mv" fx:id="mv" style="-fx-border-color: red;-fx-background-color: #e9df47" HBox.hgrow="ALWAYS">
</MediaView> </MediaView>
</children> </children>
</HBox> </HBox>