I record some .wav files from microphone, and convert it to mp3 and m4a files. These files can be played with my desktop player correctly.
Then in my JavaFX program, I play them as:
String fileUri = file.toURI().toString();
Media media = new Media(fileUri);
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.play();
But there is no sound, and no errors.
I use ffmpeg
to view them:
ffmpeg -i demo.m4a
Input #0, aac, from 'demo.m4a':
Duration: 00:00:54.00, bitrate: 132 kb/s
Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 132 kb/s
ffmpeg -i hello.mp3
Input #0, mp3, from 'hello.mp3':
Metadata:
encoder : Lavf57.83.100
Duration: 00:00:01.12, start: 0.069063, bitrate: 49 kb/s
Stream #0:0: Audio: mp3, 16000 Hz, stereo, s16p, 48 kb/s
And use this command to convert by ffmpeg:
ffmpeg -i hello.wav hello.mp3
Not sure where is wrong.
Update: finally I use this command to generate mp3 which can be played by JavaFx
ffmpeg -i hello.wav -f mp2 hello.mp3
(also can add -c:a libmp3lame
to generate smaller size mp3)
Seems like JavaFx only supports mp2
format of mp3 files.