Videos not playing when building .jar

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

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

#16 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 - 11:17 AM

No media player foundjavax.media.NoPlayerException: Cannot find a Player for :jar:file:/C:/Turing_machine.jar!/Video/mpgs/Real.mpg

this is the only trace of exception i can get (if i understand you correctly)

i have no idea how to load File so i try like this
public class Play
{
    public static void Play(String args) throws MalformedURLException
    {
        File file = new File("mpgs/Real.mpg");
        java.net.URL mediaURL = file.toURI().toURL();
        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);
         }
    }
}



and error occurred
java.io.IOException: File Not Found
java.io.IOException: File Not Found
No media player foundjavax.media.NoPlayerException: Error instantiating class: com.sun.media.protocol.file.DataSource : java.io.IOException: File Not Found

this is first time when i work with url and file and i am absolute lost. this code is part of my program and i just copy paste it so if you can be more specific what exact you need from me and what i should do.
Was This Post Helpful? 0
  • +
  • -

#17 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 13 April 2012 - 03:27 PM

I need to see the block of code that calls Play.Play. Incidentally the method name should not be the same as the class unless it's a constructor. Classes should have names that are nouns, so, 'Player' not 'Play' and methods should begin lower case and have names that are verbs.
Was This Post Helpful? 1
  • +
  • -

#18 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 - 06:18 PM

you right Play was constructor at first.

public String videa[] = new String[] {"mpgs/Real.mpg","mpgs/Lecture.mpg","mpgs/Simulation.mpg"};




if(actionListenerButton.equals("Real"))
        {
            try {
                Player.play(videa[0]);
            } catch (MalformedURLException ex) {
                Logger.getLogger(MainTuring.class.getName()).log(Level.SEVERE, null, ex);
            }
        }



public class Player
{
    public static void play(String args) throws MalformedURLException
    {
        File file = new File(args);
        java.net.URL mediaURL = file.toURI().toURL();
        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);
         }
    }
}



do you need action listener too ?
Was This Post Helpful? 0
  • +
  • -

#19 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 14 April 2012 - 03:04 AM

Are you logging to the console or to file?
Was This Post Helpful? 0
  • +
  • -

#20 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 14 April 2012 - 02:44 PM

i got no error message until i change url path to file path now i have this

java.io.IOException: File Not Found
java.io.IOException: File Not Found
No media player foundjavax.media.NoPlayerException: Error instantiating class: com.sun.media.protocol.file.DataSource : java.io.IOException: File Not Found

in console
when i use url path it work fine but when i build jar i catch exception

No media player foundjavax.media.NoPlayerException: Cannot find a Player for :jar:file:/C:/Turing_machine.jar!/Video/mpgs/Real.mpg
Was This Post Helpful? 0
  • +
  • -

#21 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 15 April 2012 - 01:04 PM

Well as i mentioned earlier, using in-jar media is inflexible. Try using a JFileChooser and get a File object from the chooser to use as the source
Was This Post Helpful? 0
  • +
  • -

#22 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 15 April 2012 - 01:51 PM

but i dont want allow user to choose file to one only use button to play file i jar
Was This Post Helpful? 0
  • +
  • -

#23 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 16 April 2012 - 02:23 AM

In that case you can use


URL mediaURL = Player.class.getResource("/mpgs/Real.mpg");


Make sure the mpgs folder is at the root of your jar
Was This Post Helpful? 0
  • +
  • -

#24 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 16 April 2012 - 03:07 PM

i have it like that by URL but it dont work in jar format

not working at all
	URL mediaURL = Player.class.getResource("/mpgs/Real.mpg");


working but not in jar and i think that my file is in jar because the size is 40 MB and the error is couldn't load media player.
	URL mediaURL = Player.class.getResource("mpgs/Real.mpg");

Was This Post Helpful? 0
  • +
  • -

#25 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 17 April 2012 - 03:06 AM

Please post the result of the following command (run from the same directory as the jar

C:\>jar tf Turing_machine.jar

This post has been edited by g00se: 17 April 2012 - 03:07 AM

Was This Post Helpful? 0
  • +
  • -

#26 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 17 April 2012 - 06:54 AM

C:\>jar tf Turing_machine.jar
META-INF/
META-INF/MANIFEST.MF
BugReport/
Lyc_Api/
Video/
Video/mpgs/
turing_machine/
turing_machine_Interface/
turing_machine_Interface/images/
turing_machine_algoritm/
BugReport/Stratahodnout.html
BugReport/SwingPaint.html
BugReport/Turing_Bugreport$BookInfo.class
BugReport/Turing_Bugreport.class
BugReport/deformacia.html
BugReport/formatovanie.html
BugReport/nahlasovanie.html
BugReport/newPanel.html
BugReport/video.html
Lyc_Api/CreateImageIcon.class
Lyc_Api/Logo_Lyc^^.jpg
Lyc_Api/ProgramerCredit.class
Video/MediaPanel.class
Video/Player.class
Video/mpgs/Lecture.mpg
Video/mpgs/Real.mpg
Video/mpgs/Simulation.mpg
turing_machine/Turing_machine$1.class
turing_machine/Turing_machine.class
turing_machine_Interface/BoundedChangeListener.class
turing_machine_Interface/MainTuring.class
turing_machine_Interface/Missing_img.class
turing_machine_Interface/Turing_machine_Teoria.class
turing_machine_Interface/Turing_machine_Tutorial$1.class
turing_machine_Interface/Turing_machine_Tutorial$ThumbnailAction.class
turing_machine_Interface/Turing_machine_Tutorial.class
turing_machine_Interface/Tutorial.html
turing_machine_Interface/images/Page1.jpg
turing_machine_Interface/images/Page2.jpg
turing_machine_Interface/images/Page3.jpg
turing_machine_Interface/images/Page4.jpg
turing_machine_Interface/images/Page5.jpg
turing_machine_Interface/images/lyc.ico
turing_machine_algoritm/TuringAlgoritm.class



Was This Post Helpful? 0
  • +
  • -

#27 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 17 April 2012 - 07:33 AM

Quote

Make sure the mpgs folder is at the root of your jar


It isn't. It really should be, so that it's separate from your code and other files. If you don't want to move it, you will have to do

URL mediaURL = Player.class.getResource("/Video/mpgs/Real.mpg");

This post has been edited by g00se: 17 April 2012 - 07:34 AM

Was This Post Helpful? 0
  • +
  • -

#28 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 17 April 2012 - 03:23 PM

Still same error

C:\Users\T.M.Lyc>java -jar "C:\Turing_machine.jar"
No media player foundjavax.media.NoPlayerException: Cannot find a Player for :ja
r:file:/C:/Turing_machine.jar!/Video/mpgs/Real.mpg

No media player foundjavax.media.NoPlayerException: Cannot find a Player for :ja
r:file:/C:/Turing_machine.jar!/Video/mpgs/Lecture.mpg


Was This Post Helpful? 0
  • +
  • -

#29 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: Videos not playing when building .jar

Posted 17 April 2012 - 03:28 PM

Alright - have you been able to play mpgs in any way with Java in code?
Was This Post Helpful? 0
  • +
  • -

#30 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 17 April 2012 - 11:55 PM

yes i am able to play this videos
URL mediaURL = Player.class.getResource("mpgs/Real.mpg");

but no luck to play after build jar.
Was This Post Helpful? 0
  • +
  • -

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