当我尝试播放任何视频时,我可以听到音频,但屏幕上没有视频。我尝试以相同的方式添加菜单,但是有效但播放器类没有正确添加到舞台上。
//这里所有的进口...... !!!
public class MyPlayerLauncher extends Application
{
static Stage stage1;
static Player player;
static ViewManager viewmanager;
public static void main(String a[])
{
launch(a);
}
public void start(Stage stage)
{
ViewManager viewmanager = new ViewManager();
Scene scene = new Scene(viewmanager, 1000, 600, Color.BLACK);
stage.setScene(scene);
stage.show();
}
}
public class ViewManager extends BorderPane
{
Button play, stop, forward, backward, next, previous, loop;
Slider volume, seekbar;
Label volume_label, start_time, end_time;
Pane bpane = new Pane();
Player player;
MenuManager menumanager = new MenuManager();
public ViewManager()
{
this.menumanager.menus();
this.setTop(menumanager.menus());
setPadding(new Insets(5,10,5,10));
play = new Button("|>");
play.setPrefWidth(70);
play.setPrefHeight(70);
play.setMinHeight(30);
play.setMinWidth(30);
stop = new Button("[]");
stop.setPrefWidth(70);
stop.setPrefHeight(70);
stop.setMinHeight(30);
stop.setMinWidth(30);
forward = new Button(">>");
forward.setPrefWidth(70);
forward.setPrefHeight(70);
forward.setMinHeight(30);
forward.setMinWidth(30);
backward = new Button("<<");
backward.setPrefWidth(70);
backward.setPrefHeight(70);
backward.setMinHeight(30);
backward.setMinWidth(30);
next = new Button(">>|");
next.setPrefWidth(70);
next.setPrefHeight(70);
next.setMinHeight(30);
next.setMinWidth(30);
previous = new Button("|<<");
previous.setPrefWidth(70);
previous.setPrefHeight(70);
previous.setMinHeight(30);
previous.setMinWidth(30);
loop = new Button("@");
loop.setPrefWidth(70);
loop.setPrefHeight(70);
loop.setMinHeight(30);
loop.setMinWidth(30);
volume = new Slider();
volume.setPrefWidth(500);
bpane.setStyle("-fx-background-color:#bfc2c7");
bpane.getChildren().addAll(play, stop, backward, forward, previous, next, loop);
this.setBottom(bpane);
}
public void play(File file)
{
String received_file = null;
try
{
received_file = file.toURI().toURL().toExternalForm();
System.out.println(received_file);
player = new Player(received_file);
setCenter(player);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
}
public class Player extends BorderPane
{
Media media;
MediaPlayer mediaplayer;
MediaView mediaview;
Pane mpane;
MenuManager mm = new MenuManager();
public Player(String file)
{
String playable_file = file;
media = new Media(playable_file);
mediaplayer = new MediaPlayer(media);
mediaview = new MediaView(mediaplayer);
mpane = new Pane();
mpane.getChildren().add(mediaview);
setCenter(mpane);
mediaplayer.play();
}
}
public class MenuManager
{
Player layer;
FileChooser filechooser;
ViewManager viewmanager;
Stage stage;
MyPlayerLauncher mm;
public Node menus()
{
MenuBar menubar = new MenuBar();
Menu file = new Menu("_File");
MenuItem open = new MenuItem("_Open");
MenuItem openmultiple = new MenuItem("_Open Multiple files");
MenuItem openfolder = new MenuItem("_Open Folder");
MenuItem quit = new MenuItem("_Quit");
file.getItems().add(open);
file.getItems().add(openmultiple);
file.getItems().add(openfolder);
file.getItems().add(quit);
menubar.getMenus().add(file);
open.setOnAction(new EventHandler<ActionEvent>()
{
public void handle(ActionEvent e)
{
stage = mm.stage1;
filechooser = new FileChooser();
File file = filechooser.showOpenDialog(stage);
if(file != null)
{
viewmanager = new ViewManager();
viewmanager.play(file);
}
else
{
System.exit(0);
}
}
});
quit.setOnAction(new EventHandler<ActionEvent>()
{
public void handle(ActionEvent e)
{
System.exit(0);
}
});
return menubar;
}
}