ADDITIONAL SYSTEM INFORMATION :
Ubuntu 22.10
OpenJFX 19
A DESCRIPTION OF THE PROBLEM :
When try to play a MP3 the MediaPlayer raises an exception: "com.sun.media.jfxmedia.MediaException: Could not create player!"
WAV files are working.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no exception and MediaPlayer plays the MP3 - like WAV
ACTUAL -
exception
---------- BEGIN SOURCE ----------
package com.sample.MediaPlayerMP3Bug;
import java.net.URL;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
public class App extends Application {
private MediaPlayer mediaPlayer;
@Override
public void init() throws Exception {
// var musicFile = "music.wav"; // works
var musicFile = "music.mp3"; // fails
URL fileUrl = getClass().getResource(musicFile);
var media = new Media(fileUrl.toString());
mediaPlayer = new MediaPlayer(media); // com.sun.media.jfxmedia.MediaException: Could not create player!
mediaPlayer.play();
}
@Override
public void start(Stage stage) {
var root = new HBox(new Label("MediaPlayer-MP3-Bug"));
stage.setScene(new Scene(root, 600, 400));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
using WAV - but it's not a viable workaround for real world applications
FREQUENCY : always