*********************************************************************
COMPLETE SOURCE CODE FOR : TestPlay.java
*********************************************************************
import javazoom.jl.player.Player;
import java.io.FileInputStream;
public class TestPlay
{
public static void main(String[]args)
{
try
{
FileInputStream fis=new FileInputStream("C:\\Documents and Settings\\UserXP\\Desktop\\01-flo_rida_(feat_david_guetta)-clab_cant_handle_me.mp3");
Player playMp3=new Player(fis);
playMp3.play();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Thank you very much for the code, works like a charm :)
ReplyDeletebut i want so have some method with which i can play my music files in mp3 format in the background of my jframe swing application....whereas your method is concerned, it doesn't allow the programme to proceed furthur till the song gets complete..
ReplyDeleteThank you very much..... helped a lot to my project....
ReplyDeleteIs there any way, so that i can play any audio format file ??
hi..what about if i want to make a converter of avi to mp3. Is it possible? tnx
ReplyDeletehopin for the reply.. :)
Hi
ReplyDeleteYour code is very excellent. It works great. Just a question:
How can I abilities like stop/pause/.... ?
Thanks
one more problem:
ReplyDeletewhen the audio is playing, every thing else stops working. I can't stop it any way. Is there a piece of code I can use to prevent that.
Try running it on a thread like this:
Deletenew Thread(new Runnable()
{
@Override
public void run()
{
try
{
Player player = new Player(new FileInputStream("media/alert.mp3"));
player.play();
}catch(FileNotFoundException fileNotFoundException)
{
fileNotFoundException.printStackTrace();
}//end catch
catch(JavaLayerException javaLayerException)
{
javaLayerException.printStackTrace();
}//end catch
}//end method run
}).start();
This will make it run on the background.
it's working.
ReplyDeletethank you...
Try running it on a thread like this:
ReplyDeletenew Thread(new Runnable()
{
@Override
public void run()
{
try
{
Player player = new Player(new FileInputStream("media/alert.mp3"));
player.play();
}catch(FileNotFoundException fileNotFoundException)
{
fileNotFoundException.printStackTrace();
}//end catch
catch(JavaLayerException javaLayerException)
{
javaLayerException.printStackTrace();
}//end catch
}//end method run
}).start();
This will make it run on the background.
anyone here knows how to code music streaming via bluetooth? this is a mobile application. if anyone knows please help me.
ReplyDeleteHow can I use this with a GUI in java? I have the graphical design, but I don't know how to use this code to match my GUI... Do I have make an instance of "TestPlay" in my GUI-class?
ReplyDelete