I've been using MediaPlayer on win10 and it works perfectly fine, but on my MacBook Air (10.13.4 (17E202)) is no sound output at all. I've already found similar problems and observed that its caused by the GC.
I tried everything avoiding this, based on answers like this one
I tried making the media player final, static, private, public, working with getter and setter, outsourcing, as a class var, as a local var but nothing is working.
I'm running on Java 9.0.4.
If I add player.setCycleCount(MediaPlayer.INDEFINITE);
the sound plays, but its looping and if I set it to 2 its working well, but my next , back, play, pause buttons are getting very weird then.
Using AudioClip instead is no option for me, because I have to use the MediaPlayer .
public class Main extends Application {
MediaPlayer player;
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane root = new BorderPane();
File file = new File("/users/xxx/desktop/xxx/Song.mp3");
Media media = new Media(file.toURI().toString());
this.player = new MediaPlayer(media);
player.play();
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
}
I would appreciate every help.