简体   繁体   中英

Javafx won't play mp3

I want to run mp3 without any videos with java.

import javafx.embed.swing.JFXPanel;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;

public class Guess {

    public static void main(String[] args) throws Exception {
        new JFXPanel();
        Media m = new Media("file:///D://Guess_the_Song//resources//new.m4a");
        MediaPlayer p = new MediaPlayer(m);
        p.play();
        
    }

}

This code doesn't lead me to any errors, but I can't hear any sound...

Try this:

path = "D:/Guess_the_Song/resources/new.m4a";
Media m = new Media(new File(path).toURI().toString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM