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

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();
@ -120,6 +141,7 @@ public class PlayerController {
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);
@ -183,6 +205,7 @@ public class PlayerController {
} }
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"));
@ -199,6 +222,7 @@ public class PlayerController {
} }
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"));
@ -215,6 +239,7 @@ public class PlayerController {
} }
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"));
@ -231,6 +256,7 @@ public class PlayerController {
} }
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();
} }
@ -451,6 +482,7 @@ public class PlayerController {
} }
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"));
@ -482,6 +514,7 @@ public class PlayerController {
} }
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>