java应用程序不会显示mediaplayer

xcitsw88  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(207)

我创建了一个类似于netflix的应用程序,当我让用户订阅某个电影时,就会出现一个黑屏。没别的了,为什么我能修好它请帮忙。。。我用同样的代码上传了另外4部电影,效果不错。

subscribe.setOnAction((ActionEvent b) -> {
                       Media media = new Media(MEDIA_URL5);
    MediaPlayer mediaPlayer2 = new MediaPlayer(media);
    MediaView mediaView2 = new MediaView(mediaPlayer2);
    Button pButton = new Button("Play");
    pButton.setOnAction(p -> {
        if (pButton.getText().equals("Play") || pButton.getText().equals("Paused")) {
            mediaPlayer2.play();
            totalTime = getTimeFormat(mediaPlayer2.getStopTime().toMillis());
            time.setMax(mediaPlayer2.getStopTime().toMillis());
            pButton.setText("Playing");
        } else {
            mediaPlayer2.pause();
            pButton.setText("Paused");
        }
    });

    Button rButton = new Button("Replay");
    rButton.setOnAction(r -> mediaPlayer2.seek(Duration.ZERO));
    Slider Volume = new Slider();
    Volume.setPrefWidth(100);
    Volume.setMaxWidth(Region.USE_PREF_SIZE);
    Volume.setMinWidth(30);
    Volume.setValue(50);
    mediaPlayer2.volumeProperty().bind(
            Volume.valueProperty().divide(100));

    time.setPrefWidth(150);
    HBox hBox2 = new HBox(10);
    hBox2.setAlignment(Pos.CENTER);
    hBox2.setPadding(new Insets(2, 0, 2, 0));
    Label lblVideoTime = new Label(getTimeFormat(0), time);

    hBox2.getChildren().addAll(pButton, rButton, new Label("Time"), 
            lblVideoTime,new Label("Volume"), Volume);

    mediaPlayer2.currentTimeProperty().addListener(d -> {
        if (!time.isValueChanging()) {
            time.setValue(mediaPlayer2.getCurrentTime().toMillis());
        }
        lblVideoTime.setText(
                getTimeFormat(mediaPlayer2.getCurrentTime().toMillis()) + "/" + totalTime);
    });
    time.valueProperty().addListener(ov -> {
        if (time.isValueChanging()) {
            mediaPlayer2.seek(new Duration(time.getValue()));
        }
    });

    BorderPane pane10 = new BorderPane();
    pane10.setCenter(mediaView2);
    pane10.setBottom(hBox2);
    pane10.autosize();
    pane10.setStyle("-fx-background-color: black");
    Scene scene11 = new Scene(pane10, 800, 800);
    primaryStage.setTitle("Bus Stop"); 
    primaryStage.setScene(scene11); 
    primaryStage.show(); 
    primaryStage.sizeToScene();
});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题