javajavafxmediabitratemediainfo

Does MediaPlayer only play mp3 files that have bit rate mode: variable?


I'm building an mp3 player app and certain mp3 files won't play. It's the same mp3 files every time that wont play. No errors are thrown and when I click to play them, everything works as if the audio is about to play, but then no audio comes out, it's like the song freezes.

Using the MediaInfo tool (from the mac app store), I compared 2 files that worked and 2 that didn't and took a screenshot of the results. (Red means the field values are different, black means they are the same)

Comparison of 2 files that worked and 2 that did not

The 2 on the left are the ones that did work and the 2 on the right are the ones that didn't work. The only difference I can see is the songs causing problems have Bit Rate Mode: Constant. Could this be whats causing problems? If so, is there a way to find an audio files Bit Rate Mode using java? and how would you change it from Constant to Variable?

Although I don't think its necessary since all my other songs work, I'll post some code below.

String songPath = "";
Media mediaFile = MediaHandler.strToMedia(songPath);
MediaHandler.newSong(mediaFile);
MediaHandler.playSong();

The MediaHandler Class:

public class MediaHandler {

    private static MediaPlayer player;
    private static Media media;


    public static MediaPlayer getPlayer(){
        return player;
    }

    public static Media strToMedia(String songPath) {
        File song = new File(songPath);
        return new Media(song.toURI().toString());
    }

    public static void newSong(Media mediaFile) {
        if (player != null){
            player.stop();
        }
        MediaHandler.media = mediaFile;
        newPlayer();
    }

    private static void newPlayer() {
       player = new MediaPlayer(media);
    }

    public static void playSong() {
        player.play();
    }
}

Solution

  • is there a way to find an audio files Bit Rate Mode using java?

    You use MediaInfo graphical interface for spotting the issue, you can also use its command line interface (calling a command line from Java) or its library (DyLib) interface (calling an API from Java).

    Get the Command line interface or the DyLib interface from MediaInfo macOS version, then call the command line or get the "glue" between Java and MediaInfo + implement Java calls to MediaInfo.