Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

javazoom mp3 help needed

807591Jun 14 2008 — edited Jun 15 2008
Hello. I have downloaded this Javazoom Jalayer mp3 program from here to use with my programs:
http://www.javazoom.net/javalayer/sources.html
I wanted to use it to play mp3 files. I made a program (below) and it's working fine in eclipse, but when I export it to a JAR, it doesn't work.

Below is a piece of code that I was using to test the javazoom thing. It will play the mp3 music.mp3 from the file Music in the same directory. It seems it stops working at "player = new Player (bis);" when it's a jar, buts it works fine in eclipse. I'm thinking I didn't export the player properly with eclipse.

So far, in order to get it to work in eclipse, all I did was add an External JAR to my java build path, and selected the downloaded jl1.0.jar. I don't think I touched anything else.

After that, I created the MusicTest program and exported my project into a jar. However, when I execute the jar, the music doesn't play.

I'm thinking that maybe theres some classpath thing that I didn't do, but I thought that the External Jar creation in eclipse was all I needed.

Can somebody help me with this problem?
import java.awt.Frame;
import java.awt.TextArea;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javazoom.jl.player.Player; // import javazoom player

public class MusicTest
{
    static Frame test;
    static TextArea text = new TextArea (20, 20);
    static Player player;
    static WindowListener musicWindow = new WindowAdapter ()  // add a windowlistener to window so that the closed button can be pressed
    {
        public void windowClosing (WindowEvent ev) 
        {
            System.exit (1);
        }
    }


    ;

    public static void main (String [] args)
    { // entry point of program
        test = new Frame ();
        test.add (text);
        test.pack ();
        test.setVisible (true);
        text.append ("Music\n");
        test.addWindowListener (musicWindow);
        String filename = "Music/music.mp3";
        try
        {
            FileInputStream fis = new FileInputStream (filename);
            text.append ("fileinputstream created\n");
            BufferedInputStream bis = new BufferedInputStream (fis);
            text.append ("bufferedimputstream created\n");
            player = new Player (bis); // <-- When i create a jar, the program stops here
            text.append ("player created\n");
        }
        catch (Exception e)
        {
            System.out.println ("Problem playing file " + filename);
            System.out.println (e);
            text.append ("Problem playing file " + filename);
            text.append (e.getMessage ());
        }
        try
        {
            text.append ("music on\n");
            player.play ();
        }
        catch (Exception e)
        {
            System.out.println (e);
            text.append (e.getMessage ());
        }
    }
}
Edited by: Integrate on Jun 13, 2008 9:27 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2008
Added on Jun 14 2008
12 comments
2,645 views