Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX MediaPlayer - Music stops after 10 seconds

Tags:

java

javafx

mp3

Here's the code, like the title says the music stops after 10ish seconds, i played the file normally in vlc or other programs, it lasts more than 5 minutes.

public void music(){
        String bip = "src/data/fjordmusic.mp3";
        Media hit = new Media(Paths.get(bip).toUri().toString());
        MediaPlayer mediaPlayer = new MediaPlayer(hit);
        mediaPlayer.play();
    }
like image 608
user2627736 Avatar asked Apr 25 '15 20:04

user2627736


1 Answers

Try AudioClip instead:

javafx.scene.media.AudioClip;

    public void music(){
        String bip = "src/data/fjordmusic.mp3";
        Media hit = new Media(Paths.get(bip).toUri().toString());
        AudioClip mediaPlayer = new AudioClip(hit.getSource());
        mediaPlayer.play();
    }
like image 121
TheBroker Avatar answered Nov 15 '22 18:11

TheBroker