skappler
skappler

Reputation: 763

Play m4a files in Java

I want to create a media player in Java. The mp3 support already works with the JLayer library but which library can play m4a files?

I read about vlcj here on stackoverflow, but this seems to depend on Swing/AWT which I wouldn't use because I want to port the application to Android later on.

Upvotes: 3

Views: 9096

Answers (3)

user3466773
user3466773

Reputation: 186

If you have Java 7 or later, you have access to the Javafx library. You can also use your media player (like iTunes or Windows Media Player) to convert to the simpler mp3 version and run that. I wouldn't recommend .wav files as they have significantly more data usage than mp3s, (which condense the file size by compressing the .wav data and omitting inaudible and otherwise garbage-y data).

import javafx.scene.media.*;
String name = "song.mp3";
Media song = new Media(name);
MediaPlayer player = new MediaPlayer(song);
player.play();

Upvotes: 0

Michael Berry
Michael Berry

Reputation: 72379

Have you looked at JAAD? It's a Javasound SPI that decodes AAC audio, I've used it with success previously.

Note that m4a is a container format, and while it usually contains (in my experience) AAC audio, in theory it could contain other formats instead.

You can find some information about getting it working without Javasound (and a test case) here.

Upvotes: 3

Daniel Kaplan
Daniel Kaplan

Reputation: 67504

This answer is indirect. I don't really know anything about m4a files. But what I have found is an open source library that can stream them as a flash server named red5. It's written in Java so theoretically you should be able to browse their code to figure out how to do it.

Hopefully someone here can give a more direct answer, this is the best I can do.

Upvotes: 0

Related Questions