0

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();
    }
}
shinjw
  • 3,329
  • 3
  • 21
  • 42
Tedious
  • 75
  • 6
  • without [mcv] there's no way to help. Unrelated: static scope for a class with state is asking for trouble (as is using static scope nearly always). – kleopatra Aug 24 '20 at 09:26
  • also, this looks like the basically same problem as in your previous question (https://stackoverflow.com/q/63543135/203657 - which you deleted), except that you advanced a bit in finding a possible reason? If so: don't delete questions, instead edit the old to add new details .. – kleopatra Aug 24 '20 at 12:19
  • @kleopatra ah ok I see, and thanks for the tips – Tedious Aug 24 '20 at 23:28

1 Answers1

0

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.

Jérôme Martinez
  • 1,118
  • 5
  • 10
  • Thanks! I didn't even recognize you could call it from the command line. I'm currently working on finishing the project then I will try implementing this and see if it helps at all. – Tedious Aug 29 '20 at 03:02