Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 JLayer mp3- Need help creating jar
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Integrate




PostPosted: Fri Jun 13, 2008 10:53 pm   Post subject: JLayer mp3- Need help creating jar

Hello. I have downloaded this JLayer thing from here:
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?

code:

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)  // if close button pressed on computer window
        {
            System.exit (1); // make it invisible
        }
    }


    ;

    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);
            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 ());
        }
    }
}

Sponsor
Sponsor
Sponsor
sponsor
Zeroth




PostPosted: Sat Jun 14, 2008 12:45 am   Post subject: Re: JLayer mp3- Need help creating jar

Umm, why don't check what directory the program is executing in? If theres no Music folder right there, then it won't find the file.
Integrate




PostPosted: Sat Jun 14, 2008 1:17 am   Post subject: RE:JLayer mp3- Need help creating jar

It should have found the correct directory, or else it would have printed something like "music.mp3 not found" in the text area. I checked by removing the music file entirely, and my program displayed the error message as predicted.

The problem is that it has found the music file, but cannot create the player.

It prints:

bufferedimputstream created

as the last line it outputs, but does not print

player created

which is the line after player = new Player (bis);. This leads me to believe something is wrong with the Player class after exporting. If something went wrong, it should have caught the error message and displayed it, but it does not, so I have no idea what's going on.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: