Getting a mp3 file to play using javafx

The files located outside the workspace should be included with file:// prefix. A simple example demonstrating the functionality is

public class Reproductor extends Application {

    public static void main(String[] args) {
        launch(args); 
    }

   @Override
   public void start(Stage stage) throws Exception {
       Media media = new Media("file:///Movies/test.mp3"); //replace /Movies/test.mp3 with your file
       MediaPlayer player = new MediaPlayer(media); 
       player.play();
   }  
 }

Leave a Comment