1

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.

Freewind
  • 193,756
  • 157
  • 432
  • 708
  • 2
    You can read which media types are supported in the package Javaodc of [`javafx.scene.media`](https://docs.oracle.com/javase/10/docs/api/javafx/scene/media/package-summary.html) (link is for Java 10). – Slaw Aug 11 '18 at 06:01
  • 2
    This is a great question, JavaFX needs improvements for sure on the Media supporting part. – GOXR3PLUS Aug 12 '18 at 14:09
  • @Slaw Thanks for the link. Actually I've read it but that doesn't fully resolve my problem. E.g. It says it support `m4a` and `aac`, but you can see my `demo.m4a` fits the requirement, but it still can't be played – Freewind Aug 13 '18 at 16:24

0 Answers0