Hei Leuts,
Ich hab ein kleines Problem.. Undzwar seitdem ich VolumeSlider und seeSlider drinne habe, funktioniert der Play button nicht.
Code:
Java
package Controller;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Slider;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.util.Duration;
// onDragDropped="#PaneDragAndDrop" fx:id="#DragAndDropPane"
public class MainFXController implements Initializable {
@FXML public static Pane DragAndDropPane;
@FXML private Slider volumeSlider;
@FXML private Slider seeSlider;
@FXML private Button btnPrevious;
@FXML private Button btnPlay;
@FXML private Button btnStop;
@FXML private Button btnNext;
Media sound = new Media(new File("src/musicmain/1.mp3").toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(sound);
@Override
public void initialize(URL location, ResourceBundle resource) {
volumeSlider.setValue(mediaPlayer.getVolume() * 100);
volumeSlider.valueProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
mediaPlayer.setVolume(volumeSlider.getValue() / 100);
}
});
mediaPlayer.currentTimeProperty().addListener(new ChangeListener<Duration>() {
@Override
public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {
seeSlider.setValue(newValue.toSeconds());
}
});
}
@FXML
protected void seeSlider(MouseEvent event) {
mediaPlayer.seek(Duration.seconds(seeSlider.getValue()));
}
@FXML
protected void btnPlay(ActionEvent event) throws IOException {
mediaPlayer.play();
}
@FXML
protected void btnStop(ActionEvent event) throws IOException {
mediaPlayer.stop();
}
}
Alles anzeigen