How To Create Own MP3 Player Using JMF - Online Article

When I used the Linux, I saw there were not any "MP3 player" which was ease to use like "Window Media Player" and other players on "Windows Platform", those are available they require plug-in or dependencies to play MP3. Here is a code sample to create your own MP3 player by using Java Media Framework 2.1 which unique functionality of "Platform Independency".

What is JMF?

Now the question arises what is JMF? This is formally known as "Java Media Framework". The Java Media Framework Application Programming Interface (JMF API) enables audio, video and other time-based media to be added to applications and applets built on Java technology. This optional package, which can capture, playback, stream, and transcode multiple media formats, extends the Java 2 Platform, Standard Edition (J2SE) for multimedia developers by providing a powerful toolkit to develop scalable, cross-platform technology.

Code Sample

import java.util.logging.*;
import javax.swing.*;

* * * @author Rajesh Kr. Gupta, Engg. C.S.E.
* Built on NetBeansIDE 6.0 */

public class MP3Player
	/*Creates a new instance of MP3Player */
	public MP3Player(){ }

	/** * @param args the command line arguments */
	public static void main(String[] args)
		{ file = new"Location of MP3 file");
			MediaLocator mrl = new MediaLocator(file.toURL()));
			Player player =;
			player.start( );
		catch (Exception ex)
			Logger.getLoggger("global").log(Level.SEVERE, null, ex);


To run this code you must installed the JMF 2.1 and Netbeans IDE 6.0. You can download and install these software's from


Basically it is a console player, which takes the input as the MP3 file location on your hard disk. You have to write location of MP3 file at place of "Location MP3 file". At this line, I created the file object of MP3 file and in the next line, I converted this file object into URL with the help of 'toURL( )' method and pass this URL into the constructor of 'MediaLoactor' class to instantiate the object. The purpose of doing this is to inform the compiler given input file location is a media location. After that this media resource locator object (mrl) passed into the 'Player' instantiation method 'createRealizedPlayer()' that will instatiate the player object of given media location. At the next line player will be started with the help of 'start()' method.

This code block should be surrounded by 'try-catch' beacaue it may thorow some exceptions like: File not found, File is not media file etc

About the Author:

No further information.


raneed alhasanat on 2012-09-16 17:23:36 wrote,

nice pic. like