Listen to your MP3 songs on your PC through Java MP3 Player!!
11:27 AM
Posted by Sai Subramanyam
We all listen to songs daily in our PC,majority of them or all of them are mp3 formats.We have different kinds of Media Players in Internet.But,regardless of all those applications if we use a Media Player made with Java,how it will be?
Sounds Intresting right?
Two years ago when I am searching through java websites I came across this intresting application called Java MP3 Player.Even though its not very userfriendly,its a very good application which is developed using basic Swing capabilities.
You can see the source code here :
You can execute this first by grouping both these classes in a single folder,compiling the Main class and try executing it.This application mainly usef JMF(Java Media Framework) which is used to create Players and several other media related applications.
In this,we used BasicPlayer class and applied some techniques of Swing!
You can download the program full source code here .To execute this full source code you need NetBeans Developer IDE.
We will see more Java Applications in my next posts!!
Hope you liked it!
Stay Tuned!!
Sounds Intresting right?
Two years ago when I am searching through java websites I came across this intresting application called Java MP3 Player.Even though its not very userfriendly,its a very good application which is developed using basic Swing capabilities.
You can see the source code here :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mediaplayer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javazoom.jlgui.basicplayer.*;
/**
*
* @author Administrator
*/
class JavaMediaPlayer extends JPanel implements BasicPlayerListener{
private JProgressBar jpb;
private JButton play;
private BasicPlayer player=new BasicPlayer();;
private String imagePath="images/";
private static int p=0;
private static boolean playBoolean=true;
JavaMediaPlayer(){
//setLayout(new FlowLayout(FlowLayout.LEFT,3,3));
setLayout(null);
player.addBasicPlayerListener(this);
play=new JButton(new ImageIcon(imagePath+"pause.png"));
play.setToolTipText("pause");play.setBounds(2,2,20,20);
play.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
if(playBoolean){
pausePlaying();
play.setToolTipText("Play");
play.setIcon(new ImageIcon(imagePath+"play.png"));
playBoolean=false;
return;
}
if(playBoolean==false){
resumePlaying();
play.setToolTipText("Pause");
play.setIcon(new ImageIcon(imagePath+"pause.png"));
playBoolean=true;
return;
}
}
});
jpb=new JProgressBar();
jpb.setBorderPainted(true);
jpb.setBounds(25,2,280,20);
add(play);
add(jpb);
}
public void startPlaying(String fileName){
try{
play.setIcon(new ImageIcon(imagePath+"pause.png"));
play.setToolTipText("Pause");
playBoolean=true;
player.open(new File(fileName));
player.play();//actually play file
}
catch(Exception d){
System.out.println(d);
}
}
private void pausePlaying(){
try{
player.pause();
}
catch(Exception e){
System.out.println(e);
}
}
private void stopPlaying(){
try{
player.stop();
jpb.setValue(0);
}
catch(Exception d){
System.out.println(d);
}
}
private void resumePlaying(){
try{
player.resume();
}
catch(Exception d){
System.out.println(d);
}
}
public void opened(Object arg0, Map map) {
String k=map.get("audio.length.frames").toString();
jpb.setMaximum(Integer.parseInt(k)-15);
}
public void progress(int arg0, long arg1, byte[] arg2, Map map) {
String s=map.get("mp3.frame").toString();
int k=(p-(Integer.parseInt(s))*(-1));
jpb.setValue(k);
}
public void stateUpdated(BasicPlayerEvent bpev) {
if(bpev.getCode()==BasicPlayerEvent.STOPPED){
// Something here
}
}
public void setController(BasicController arg0) {
// throw new UnsupportedOperationException("Not supported yet.");
}
}
This is the JavaMP3Player class.The following code is the Main class./* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mediaplayer; import javax.swing.*; /** * * @author Tutorial Jinni */ class Main { /** * @param args the command line arguments */ public static void main(String[] args) { JFrame f=new JFrame(); JavaMediaPlayer jmp=new JavaMediaPlayer(); f.add(jmp); f.setDefaultCloseOperation(3); f.setVisible(true); f.setSize(330,60); f.setTitle("Java Media Player - Tutorial Jinni"); jmp.startPlaying("Song-location.mp3"); } }
You can execute this first by grouping both these classes in a single folder,compiling the Main class and try executing it.This application mainly usef JMF(Java Media Framework) which is used to create Players and several other media related applications.
In this,we used BasicPlayer class and applied some techniques of Swing!
You can download the program full source code here .To execute this full source code you need NetBeans Developer IDE.
We will see more Java Applications in my next posts!!
Hope you liked it!
Stay Tuned!!
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
Java Applications
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Subscribe to:
Post Comments (Atom)
August 10, 2011 at 10:20 AM
Very very nice
March 28, 2016 at 7:11 PM
Hi man good job. Have an Email?
March 28, 2016 at 7:13 PM
My blog about Java too https://isjavado.wordpress.com/contents/
May 10, 2016 at 11:24 AM
How can I use InputStream in this class?
November 30, 2016 at 1:53 AM
when you copy paste at least give reference to the original source
http://tutorialjinni.blogspot.com/2010/08/java-media-player-mp3-player.html