Videos not playing when building .jar

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 5914 Views - Last Post: 21 April 2012 - 04:06 AM Rate Topic: -----

#1 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Videos not playing when building .jar

Posted 24 October 2009 - 05:35 AM

Hi,

I'm self taught in Java and fairly new to it. I created my first big project during this year and it's basically a library system connected to a database of books and it shows you every books cover blahblah. I also have some videos and music.

Everything works while the program is in the Netbeans builder. All videos and music play fine no errors. I've imported the java media framework jars (fobs.jar and jmf.jar) into the program libraries and thereafter all videos work fine. Problem is when I build the project and go into the dist folder, the program .jar is there and a 'lib' folder with the jars i imported.

But when running the jar, videos will not work. I get a 'no media player found exception'. Is there something I'm missing? This is the first time i've ever built a project so not sure what I'm doing wrong.

I've tried placing the jars in the same folder as the main jar, tried importing them into the main project and I've run out of ideas. Can anyone help please?

This is the manifest for the jar:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.0-b16 (Sun Microsystems Inc.)
Main-Class: BookSystem.GUI
Class-Path: lib/beansbinding-1.2.1.jar lib/jmf.jar lib/fobs4jmf.jar
X-COMMENT: Main-Class will be added automatically by build

As you can see the jmf.jar and fobs4jmf.jar are located in the classpath.

Also, I was wondering if it's possible to play mp3 files without using JMF? It's just that I'm using wav files for songs and well they are like 100 megs each :<

Is This A Good Question/Topic? 0
  • +

Replies To: Videos not playing when building .jar

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Videos not playing when building .jar

Posted 24 October 2009 - 03:42 PM

Are your videos included in the .jar file ?
How do you try to open them ? Not with the path based on the file system I hope ?
Was This Post Helpful? 0
  • +
  • -

#3 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Re: Videos not playing when building .jar

Posted 25 October 2009 - 09:39 AM

View Postpbl, on 24 Oct, 2009 - 02:42 PM, said:

Are your videos included in the .jar file ?
How do you try to open them ? Not with the path based on the file system I hope ?


I place a folder in the C drive with all program images/videos and run them with a String file path.

So they are not in the jar.

How can I place them in the jar? I don't know any other way to play videos.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Videos not playing when building .jar

Posted 25 October 2009 - 12:49 PM

A .jar has a directory structure

if your .class files are in directory /MyJava
you can create a subrirectory /MyJava/MyVideos and put your videos there

now if you jar * when you are in /MyJava
in your program the path to your videos will be one directory below in "MyVideos/videoFile"
Was This Post Helpful? 0
  • +
  • -

#5 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Re: Videos not playing when building .jar

Posted 25 October 2009 - 02:59 PM

View Postpbl, on 25 Oct, 2009 - 11:49 AM, said:

A .jar has a directory structure

if your .class files are in directory /MyJava
you can create a subrirectory /MyJava/MyVideos and put your videos there

now if you jar * when you are in /MyJava
in your program the path to your videos will be one directory below in "MyVideos/videoFile"


I think I am building my jar wrong.

I have a netbeans project and within that project folder ("/MyJava") I have created the textfiles that the program needs and also I have a sub directory /MyJava/Music. When I build my jar, those textfiles and music do NOT become 'part' of the .jar. I simply get a .jar that has all the classes but I need to manually put the textfiles and music into the same folder as the .jar for everything to work correctly. So I understand what you are saying, but I don't know how to make everything become a neat little .jar. The current method I use is to go into Netbeans, build my project and then go to the dist folder of my project and there's the program .jar and its libraries but no text files/music.

Thanks
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Videos not playing when building .jar

Posted 25 October 2009 - 03:29 PM

Not familiar with Netbeans but in Eclipse you cannot just add files and directories and assume they will be put in the .jar file
You have to "import" them from the Eclipse menu Import so those files will be included in the project ans so into the .jar file

I always generate my .jar file "by hand" from the console prompt not relaying on the IDE
That way you are always sure of what is it in or not
OK a little learning curve but then you know what you are doing

Put that link in your Favorites

http://java.sun.com/...deployment/jar/

that is all what you have to know
Was This Post Helpful? 1
  • +
  • -

#7 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Re: Videos not playing when building .jar

Posted 26 October 2009 - 12:17 AM

Thanks, I will try my best.
Was This Post Helpful? 0
  • +
  • -

#8 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Re: Videos not playing when building .jar

Posted 03 November 2009 - 09:14 AM

Hi, I worked out how to create .jar files using cmd and I've tried creating a manifest file. However, when running my I get the message: Cannot find the main class BookSystem.GUI, program will now exist.

The files 'GUI.form' and 'GUI.java' are in my working directory and they are added to the jar, what am i doing wrong?
Was This Post Helpful? 0
  • +
  • -

#9 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Re: Videos not playing when building .jar

Posted 03 November 2009 - 09:39 AM

Let me explain a bit more...my working directory is the 'build' folder of my netbeans project. I don't what netbeans has done because all my classes are split into smaller files eg my one GUI class has 208 seperate .class fiels:

from
GUI$1.class
...
..
all the way to
..
GUI$208.class

so I'm created my jar with jar cvfm myProgram.jar MANIFEST.mf *.class *.java

my manifest is as follows:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.0-b16 (Sun Microsystems Inc.)
Main-Class: BookSystem.GUI
Class-Path: beansbinding-1.2.1.jar jmf.jar fobs4jmf.jar jl1.0.jar mp3spi1.9.4.jar tritonus_share.jar
X-COMMENT: Main-Class will be added automatically by build


I just copied the manifest that netbeans created when I press 'build'. I think because my main class is so huge it has so many different parents it can't find which one to use? I have no idea, please help.
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Videos not playing when building .jar

Posted 03 November 2009 - 08:25 PM

Main-Class: BookSystem.GUI

That means that your GUI.java file has the statement

package BookSystem

and that GUI.class is under the subdirectory \BookSystem
from where you jar the whole stuff

This post has been edited by pbl: 03 November 2009 - 10:29 PM

Was This Post Helpful? 0
  • +
  • -

#11 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Re: Videos not playing when building .jar

Posted 04 November 2009 - 01:53 AM

Yes, but I think I'm using the wrong cmd command.

I tried creating a jar for a simple project with the same problem. My manifest file is:

Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Main-Class: playMp3s.JLayerPlayer

My path is set to a folder with JLayerPlayer.class and the manifest file.

I type jar cvfm prog.jar manifest.mf *.class

It creates a jar but it does not have JLayerPlayer.class within it.. but the cmd log says

'added manifest'
'adding JLayerPlayer.class (in = 2571) (out = 1265)(deflated 50%)

The jar says 'Could not find the main class playMp3s.JLayerPlayer. Program will now exit.'
Was This Post Helpful? 0
  • +
  • -

#12 Awoken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-March 09

Re: Videos not playing when building .jar

Posted 04 November 2009 - 03:07 AM

I fixed it, went into my classes and deleted 'package booksystem;', moved them all to the default package and just put all the classes, the manifest and the lib into one folder and created a jar that worked correctly.

However, the jar runs but now my code is acting up. The program crashes at initComponents(); I suspect my component code is way too large.
Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Videos not playing when building .jar

Posted 04 November 2009 - 05:27 PM

View PostAwoken, on 4 Nov, 2009 - 12:53 AM, said:

Yes, but I think I'm using the wrong cmd command.

I tried creating a jar for a simple project with the same problem. My manifest file is:

Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Main-Class: playMp3s.JLayerPlayer

My path is set to a folder with JLayerPlayer.class and the manifest file.

I type jar cvfm prog.jar manifest.mf *.class

It creates a jar but it does not have JLayerPlayer.class within it.. but the cmd log says

'added manifest'
'adding JLayerPlayer.class (in = 2571) (out = 1265)(deflated 50%)

The jar says 'Could not find the main class playMp3s.JLayerPlayer. Program will now exit.'


package are like directory

if you type: jar cvfm prog.jar manifest.mf *.class
first the order of the parameter should be
jar cvfm manifest.mf prog.jar *.class

then your .class files are in the same directory ...

the command should be

jar cvfm manifest.mf prog.jar *.class playMp3s

because your JLayerPlayer.class should be one directory below into \playMp3s

Again if you have

package abc

class xyz {



it means that you have to be in the directory that owns the subdiirectory \abc that contains xyz.class
before issuing your jar command

jar cvfm manifest.mf MyJar.jar abc

which says put directory abc in the .jar file

and the manifest file says that main class is in abc.xyz which means one directory below in \abc
Was This Post Helpful? 0
  • +
  • -

#14 Lyc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-April 12

Re: Videos not playing when building .jar

Posted 13 April 2012 - 04:32 AM

I have the same issue videos works fine in netbean but after building jar file it wont load media player. I am pretty sure that my videos are in jar package because the size is 50 mb. I have no ideas how to sort this problem out. I try to add library to jar but no change still get NoPlayerException. So i asking how can i play my videos in jar file?

And one problem occurred too when i play video it play fine but without sound.

I have package video where code is and video.mpgs where videos are store i run them from action listener
{
   Play.Play("mpgs/real");
}


public class Play
{
    public static void Play(String args)
    {
        java.net.URL mediaURL = Play.class.getResource(args);
        if ( mediaURL != null )
        {
            JFrame mediaTest = new JFrame("Turing Media Center");
            mediaTest.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            MediaPanel mediaPanel = new MediaPanel(mediaURL);
            mediaTest.add(mediaPanel);
            mediaTest.setSize(300, 300);
            mediaTest.setVisible(true);
         }
    }
}


public class MediaPanel extends JPanel
{
    public MediaPanel( URL mediaURL )
    {
        setLayout( new BorderLayout() );
        Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
        try
        {
            Player mediaPlayer = Manager.createRealizedPlayer( mediaURL );
            Component video = mediaPlayer.getVisualComponent();
            Component controls = mediaPlayer.getControlPanelComponent();
            if ( video != null ) add( video, BorderLayout.CENTER ); 
            if ( controls != null ) add( controls, BorderLayout.SOUTH ); 
            mediaPlayer.start(); 
         }
         catch ( NoPlayerException noPlayerException )
         {
             System.err.println( "No media player found" );
         }
         catch ( CannotRealizeException cannotRealizeException )
         {
             System.err.println( "Could not realize media player" );
         }
         catch ( IOException iOException )
         {
             System.err.println( "Error reading from the source" );
         }
    }
} 


Was This Post Helpful? 0
  • +
  • -

#15 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2559
  • View blog
  • Posts: 10,687
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 13 April 2012 - 06:27 AM

a. please post the full stack trace of the exception
b.

Quote

java.net.URL mediaURL = Play.class.getResource(args);

I'm assuming that url represents a media file. Loading the resource in such a way is going to limit you to what is contained in the jar, which would make media playing pretty useless really. You need to load by File or your choices are going to be limited
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3