ArnavKumar
Posts: 11
Joined: Mon Oct 28, 2013 10:23 am

How to play Mp3 and Mp4 using Java?

Tue Nov 05, 2013 10:38 am

Is there any open source for java to play Mp3 or Mp4 using my java code?

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: How to play Mp3 and Mp4 using Java?

Thu Nov 07, 2013 12:00 pm

There is no mp3 decoder found in the Java JRE thus you need to use a third party project that at least enable mp3 & mp4 decoding.

JLayer is a java decode for mp3 files.
http://www.javazoom.net/javalayer/javalayer.html
You need to combine JLayer with your own audio output in order to create a mp3 player.
Example here JLayer is used to create a tiny java mp3 player applet:
appletviewer http://www.javazoom.net/applets/tinypla ... layer.html


The JogAmp JOGL and JOAL project provides a GLMediaPlayer class can decode and playback both mp3 and mp4 files, GLMediaPlayer uses the system installed libav/libffmpeg library’s to do the mp3 & mp4 decoding
mp4 video is rendered using OpenGL ES and
decoded mp3 audio is sent to the pi sound-card using OpenAL.
http://jogamp.org/

Example usage of JogAmp GLMediaPlayer using one of the examples found inside the jogl-test.jar
java -cp joal.jar:jogl-test.jar:gluegen-rt.jar:jogl-all.jar com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube -url file:///home/pi/test.mp3
More examples on how to setup and use JogAmp from the command line on the pi:
https://gist.github.com/xranby/55de4fd65bfadae26203


It is also possible to make Java start a command line tool that both display video and do audio playback like omxplayer (mp4 video), mpg321 (mp3 audio), vlc (mp3 & mp4) command line tools using System.getRuntime().exec()
http://docs.oracle.com/javase/7/docs/ap ... .String%29
For example the JavaFX DukePad uses mpg321 under the hood to playback mp3 files
https://wiki.openjdk.java.net/display/OpenJFX/DukePad
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

ArnavKumar
Posts: 11
Joined: Mon Oct 28, 2013 10:23 am

Re: How to play Mp3 and Mp4 using Java?

Sat Nov 09, 2013 8:48 am

xranby wrote:There is no mp3 decoder found in the Java JRE thus you need to use a third party project that at least enable mp3 & mp4 decoding.

JLayer is a java decode for mp3 files.
http://www.javazoom.net/javalayer/javalayer.html
You need to combine JLayer with your own audio output in order to create a mp3 player.
Example here JLayer is used to create a tiny java mp3 player applet:
appletviewer http://www.javazoom.net/applets/tinypla ... layer.html


The JogAmp JOGL and JOAL project provides a GLMediaPlayer class can decode and playback both mp3 and mp4 files, GLMediaPlayer uses the system installed libav/libffmpeg library’s to do the mp3 & mp4 decoding
mp4 video is rendered using OpenGL ES and
decoded mp3 audio is sent to the pi sound-card using OpenAL.
http://jogamp.org/

Example usage of JogAmp GLMediaPlayer using one of the examples found inside the jogl-test.jar
java -cp joal.jar:jogl-test.jar:gluegen-rt.jar:jogl-all.jar com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube -url file:///home/pi/test.mp3
More examples on how to setup and use JogAmp from the command line on the pi:
https://gist.github.com/xranby/55de4fd65bfadae26203


It is also possible to make Java start a command line tool that both display video and do audio playback like omxplayer (mp4 video), mpg321 (mp3 audio), vlc (mp3 & mp4) command line tools using System.getRuntime().exec()
http://docs.oracle.com/javase/7/docs/ap ... .String%29
For example the JavaFX DukePad uses mpg321 under the hood to playback mp3 files
https://wiki.openjdk.java.net/display/OpenJFX/DukePad
Thank you very much for your help
TechKnow Heights

sirkope
Posts: 17
Joined: Wed Jun 13, 2012 7:39 pm

Re: How to play Mp3 and Mp4 using Java?

Tue Nov 12, 2013 7:28 am

xranby wrote: For example the JavaFX DukePad uses mpg321 under the hood to playback mp3 files
https://wiki.openjdk.java.net/display/OpenJFX/DukePad
Hello,

Could you compile DukePad sources?
I've tried to follow the wiki page you mentioned, but I failed (like a few of us here :http://www.raspberrypi.org/phpBB3/viewt ... it=dukepad)

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: How to play Mp3 and Mp4 using Java?

Tue Nov 12, 2013 2:51 pm

sirkope wrote:
xranby wrote: For example the JavaFX DukePad uses mpg321 under the hood to playback mp3 files
https://wiki.openjdk.java.net/display/OpenJFX/DukePad
Hello,

Could you compile DukePad sources?
I've tried to follow the wiki page you mentioned, but I failed (like a few of us here :http://www.raspberrypi.org/phpBB3/viewt ... it=dukepad)
Yes I am able to compile the Duke Pad sources. I have update the thread you linked with further instructions.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

ArnavKumar
Posts: 11
Joined: Mon Oct 28, 2013 10:23 am

Re: How to play Mp3 and Mp4 using Java?

Tue Nov 19, 2013 12:35 pm

One can use "Java Media Framework (JMF)" for creating video player and mp3 player in java.

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: How to play Mp3 and Mp4 using Java?

Wed Nov 20, 2013 9:32 am

ArnavKumar wrote:
ArnavKumar wrote:Is there any open source for java to play Mp3 or Mp4 using my java code?
One can use "Java Media Framework (JMF)" for creating video player and mp3 player in java.
Please note that JMF is not available under a free software license, the Sun Community Source Licensing lacks essential freedoms such as publication of modified versions.
http://www.oracle.com/technetwork/java/ ... #jmfsource


One alternative is FMJ that implements the same API compared to JMF under a free software license, LGPL.
http://fmj-sf.net/

Both variants need recompilation of its native code before they can be used on ARM Linux systems such as the Pi.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

henrik
Posts: 65
Joined: Tue Dec 18, 2012 4:24 pm

Re: How to play Mp3 and Mp4 using Java?

Fri Dec 06, 2013 7:21 pm

xranby wrote:
ArnavKumar wrote:
ArnavKumar wrote:Is there any open source for java to play Mp3 or Mp4 using my java code?
One can use "Java Media Framework (JMF)" for creating video player and mp3 player in java.
Please note that JMF is not available under a free software license, the Sun Community Source Licensing lacks essential freedoms such as publication of modified versions.
http://www.oracle.com/technetwork/java/ ... #jmfsource
More importantly, JMF is old and not maintained. I would not recommend using it. Starting with JavaFX/OpenJFX and the DukePad sources (GPL, BSD) seems like a better idea.

Henrik Stahl
Oracle Java team

Return to “Java”