Ползунок громкости JavaFx не меняет громкость.Объем остается неизменным - PullRequest
0 голосов
/ 20 мая 2019

Итак, для моего классного проекта я создаю игру. Я хочу добавить слайдер громкости, чтобы изменить громкость музыки. Я очень застрял здесь. Пожалуйста, помогите мне.

Я читал урок и смог отобразить его на экране. Но громкость не меняется, хотя я сдвигаю панель. Может кто-нибудь дать мне совет? Спасибо.

private Scene createOptionScene() {
        String path = "E:\\All Computer Science Materials\\Java 240 Project\\PrinceFX\\Music\\"
                + songs.getSong(1) + ".mp3";
        Media media = new Media(new File(path).toURI().toString());
        currentPlay = new AudioClip(media.getSource());
        currentPlay.setCycleCount(MediaPlayer.INDEFINITE);
        currentPlay.play();


    // Volume Control
    volumeSlider.setValue(currentPlay.getVolume() * 100);
    volumeSlider.valueProperty().addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable observable) {
            currentPlay.setVolume(volumeSlider.getValue() / 100);
        }
    });

    HBox temp = new HBox();
    temp.getChildren().addAll(volumeSlider);
    temp.setTranslateX(850);
    temp.setTranslateY(410);
    volumeSlider.setMinWidth(300);



    Image image = new Image(new File("E:\\All Computer Science Materials\\" +
            "Java 240 Project\\PrinceFX\\image\\" + picture.getImage(2) + ".png").toURI().toString());
    //Setting the image view
    ImageView imageView = new ImageView(image);

    //Setting the position of the image
    imageView.setX(0);
    imageView.setY(0);
    //setting the fit height and width of the image view
    imageView.setFitHeight(primaryScreenBounds.getHeight());
    imageView.setFitWidth(primaryScreenBounds.getWidth());
    //Setting the preserve ratio of the image view
    imageView.setPreserveRatio(true);

    Label labelOption = new Label();
    Button goBack = new Button("Go Back to Main");
    goBack.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            currentPlay.stop();
            sceneStart = createStartScene();
            stageOne.setScene(sceneStart);
        }
    });

    // Button to the main page.
    HBox layoutOp = new HBox(15);
    layoutOp.getChildren().addAll(labelOption, goBack);

    // Button coordinate.
    layoutOp.setTranslateX(1400);
    layoutOp.setTranslateY(750);

    Group gOption = new Group(imageView, layoutOp, temp);
    return new Scene(gOption, 200, 200);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...