JVLC JInternalFrame

Microsoft Windows specific usage questions
Forum rules
Please post only Windows specific questions in this forum category. If you don't know where to post, please read the different forums' rules. Thanks.
Gawain
Blank Cone
Blank Cone
Posts: 31
Joined: 08 Jan 2009 11:38
VLC version: 0.9.8a - 1.0.0
Operating System: Windows XP

JVLC JInternalFrame

Postby Gawain » 08 Jan 2009 12:45

Hi there,
I'm working on a project where I need to play a video in an internal frame. Has someone a working example with the current version of jvlc? I'm using "version 1.0.0-git-20081211-0005" at the moment.

My problem is, that my video sometimes disappears suddenly. I figured out that it's always happens when I try to activate the internal frame by clicking on it or click on a button within the internal frame, but it also happen without doing anything. Is it possible that the video has a problem, when the canvas looses the focus or when the frame is repainted?

It would be great if someone has any ideas for helping me.

Thanks a lot!
Gawain

Gawain
Blank Cone
Blank Cone
Posts: 31
Joined: 08 Jan 2009 11:38
VLC version: 0.9.8a - 1.0.0
Operating System: Windows XP

Re: JVLC JInternalFrame

Postby Gawain » 16 Jan 2009 13:11

I figured out, that it's probably a java problem and not a jvlc thing. Has someone similar experience with JInternalFrames and jvlc?

317070
Blank Cone
Blank Cone
Posts: 10
Joined: 21 Feb 2009 23:50

Re: JVLC JInternalFrame

Postby 317070 » 22 Feb 2009 21:01

Yep, I have the same issue with the canvas inside a JFrame... if you resize the frame or move the frame or something, it will simply suddenly close the ffmpeg codec...

Also, it will take ages to load. I hope you have found a way to solve this issue? The code I use comes from another application which does work fine without problems... maybe it has something to do with a lack of system-time or something...

Did you find a solution for this issue?

Jonas

317070
Blank Cone
Blank Cone
Posts: 10
Joined: 21 Feb 2009 23:50

Re: JVLC JInternalFrame

Postby 317070 » 23 Feb 2009 14:30

Hmm, the problem is not Java-related, as the following piece of code can show:

Code: Select all

package MP3player; import java.awt.Canvas; import java.awt.EventQueue; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; import java.io.IOException; import java.lang.management.GarbageCollectorMXBean; import java.lang.reflect.*; import javax.swing.JFrame; import org.videolan.jvlc.JVLC; import org.videolan.jvlc.LoggerVerbosityLevel; import org.videolan.jvlc.MediaDescriptor; import org.videolan.jvlc.MediaPlayer; import org.videolan.jvlc.Playlist; import com.sun.jna.Native; import com.sun.jna.NativeLibrary; import filePackage.MP3FileInformation; public class PlayVLCVideoFrame extends JFrame{ static Canvas canvas; private static JVLC jvlc; final private static String DEFAULTPATH = "C:/Program Files/UltraStar Deluxe/Songs/new songs/Radiohead - Creep [VIDEO]/Radiohead - Creep [VD#0].avi"; public static void main(String[] arguments) throws Exception { String loc = DEFAULTPATH; PlayVLCVideoFrame vlc = new PlayVLCVideoFrame(loc); } public PlayVLCVideoFrame(MP3FileInformation mp3) { this(mp3.getVideo()); } public PlayVLCVideoFrame() { System.out.println("Trying to load a video, cross fingers..."); canvas = new Canvas(); this.add(canvas); this.setAlwaysOnTop(true); this.setVisible(true); this.addWindowListener(new WindowListener(){ @Override public void windowActivated(WindowEvent arg0) { } @Override public void windowClosed(WindowEvent arg0) { } @Override public void windowClosing(WindowEvent arg0) { try{ getJvlc().release(); }catch(Exception e){ System.out.println("problem destroying"); }finally{ killJvlc(); } } @Override public void windowDeactivated(WindowEvent arg0) { } @Override public void windowDeiconified(WindowEvent arg0) { } @Override public void windowIconified(WindowEvent arg0) { } @Override public void windowOpened(WindowEvent arg0) { } }); this.setSize(200,200); this.setResizable(false); } private static JVLC getJvlc(){ return jvlc; } private static void killJvlc(){ jvlc=null; System.gc(); } public PlayVLCVideoFrame(String location){ this(); System.out.println("In an event (thread safe?)="+EventQueue.isDispatchThread()); File f = new File(location); System.out.println("bestaat " + location + " ? " + f.exists()); String[] args = new String[]{"-vvv","--plugin-path=c:\\Program Files\\VideoLAN\\VLC\\plugins"}; while(jvlc!=null) { try{ System.out.println("Releasing jvlc"); jvlc.release(); killJvlc(); }catch(Exception e){ e.printStackTrace(); } } System.out.println("file://"+location.replace("\\", "/")); jvlc = new JVLC(args); jvlc.setLogVerbosity(LoggerVerbosityLevel.ERROR); MediaDescriptor mediaDescriptor = new MediaDescriptor( jvlc, "file://"+location.replace("\\", "/")); System.out.println(mediaDescriptor.getMrl()); // mediaDescriptor.addOption(":sout=#transcode{vcodec=WMV2,vb=800,scale=0.25,acodec=wma,ab=128,channels=2}:duplicate{dst=display,dst=std{access=http,mux=asf,dst=:8080}}"); // mediaDescriptor.addOption(""); mediaDescriptor .addOption(":sout=#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mp3,ab=128,channels=2}"); mediaDescriptor .addOption(":sout=#duplicate{dst=display,dst=std{access=http,mux=ts,dst=:8080}}"); MediaPlayer mediaInstance = mediaDescriptor.getMediaPlayer(); mediaInstance.play(); jvlc.setVideoOutput(canvas); System.out.println("\n done \n"); } }
it will always work when run from the main-method, but not always when run from another program, but the code which is running is equal. So the problem is something with JVLC or VLC, and I think the latter because I usually get this exception:
*** LibVLC Exception not handled: No active input
Set a breakpoint in 'libvlc_exception_not_handled' to debug.
[00000403] main access out: creating httpd
[00000409] main demux warning: no access_demux module matched "file"
[00000411] avi stream warning: unknown chunk (not loaded)
[00000411] avi stream warning: unknown chunk (not unloaded)
and then, nothing.....

So, my question:
- Might it have something to do with threads waiting for each other? I sometimes get the message "xxx not receiving input, closing..." or something (see following quote) after which it stops trying to play the video.
*** LibVLC Exception not handled: No active input
Set a breakpoint in 'libvlc_exception_not_handled' to debug.
[00000403] main access out: creating httpd
[00000409] main demux warning: no access_demux module matched "file"
[00000411] avi stream warning: unknown chunk (not loaded)
[00000407] main mux warning: late buffer for mux input (189000)
[00000407] main mux warning: late buffer for mux input (167000)
[00000407] main mux warning: late buffer for mux input (144000)
[00000414] packetizer_mpeg4video packetizer warning: waiting for VOL
[00000414] packetizer_mpeg4video packetizer warning: waiting for VOL
[00000407] main mux warning: late buffer for mux input (120000)
[00000407] main mux warning: late buffer for mux input (96000)
[00000407] main mux warning: late buffer for mux input (72000)
[00000407] main mux warning: late buffer for mux input (1642000)
[00000411] avi stream warning: unknown chunk (not unloaded)
[00000407] main mux warning: no more input streams for this mux
-Is it possible that when run on a (too?) slow computer, VLC will instead of play in chunks and bits, or pause untill fully loaded, just will stop playing? That will explain why the video won't work from my (quite big) program while it works in a tiny one. Is there a way to speed this up (like add "scaling" or something to the command line parameters of VLC.) I am trying to play from my harddisk btw, so that shouldn't be an issue of the lack of speed...

-sometimes the video plays (for a few seconds). The console output is like following. Maybe someone can help me further from this?
*** LibVLC Exception not handled: No active input
Set a breakpoint in 'libvlc_exception_not_handled' to debug.
[00000403] main access out: creating httpd
[00000409] main demux warning: no access_demux module matched "file"
[00000411] avi stream warning: unknown chunk (not loaded)
[00000414] packetizer_mpeg4video packetizer warning: waiting for VOL
[00000414] packetizer_mpeg4video packetizer warning: waiting for VOL
Fontconfig error: Cannot load default config file
[00000500] main video output warning: late picture skipped (223000)
[00000500] main video output warning: late picture skipped (183000)
[00000500] main video output warning: late picture skipped (103000)
[00000500] main video output warning: late picture skipped (63000)
[00000500] main video output warning: late picture skipped (43000)
[00000500] main video output warning: late picture skipped (3000)
//At this time the video plays for a few seconds.
[00000411] avi stream warning: unknown chunk (not unloaded)
[00000407] main mux warning: no more input streams for this mux
//Now it has stopped playing.
I am quite desperate for a solution, so ANY help at all is welcome. Even a good guess is considered very helpful as I am a hobby programmer who's hobby-project is now stalled.

Yours sincerely,

Jonas

317070
Blank Cone
Blank Cone
Posts: 10
Joined: 21 Feb 2009 23:50

Re: JVLC JInternalFrame

Postby 317070 » 23 Feb 2009 16:17

Hmm, an update to the situation.

Does anyone see what can cause this difference in the console between working code and non-working code?
Working code:
*** LibVLC Exception not handled: No active input
Set a breakpoint in 'libvlc_exception_not_handled' to debug.
[00000399] main demux warning: no access_demux module matched "file"
[00000401] avi stream warning: unknown chunk (not loaded)
[00000404] packetizer_mpeg4video packetizer warning: waiting for VOL
[00000404] packetizer_mpeg4video packetizer warning: waiting for VOL
Not working code:
*** LibVLC Exception not handled: No active input
Set a breakpoint in 'libvlc_exception_not_handled' to debug.
[00000399] main demux warning: no access_demux module matched "file"
[00000401] avi stream warning: unknown chunk (not loaded)
[00000426] main packetizer error: cannot create packetizer output (mpga)
[00000404] packetizer_mpeg4video packetizer warning: waiting for VOL
[00000404] packetizer_mpeg4video packetizer warning: waiting for VOL
Fontconfig error: Cannot load default config file
[00000401] avi stream warning: unknown chunk (not unloaded)
command-line parameters are in both cases: "-vvv","--noaudio","--plugin-path=c:\\Program Files\\VideoLAN\\VLC\\plugins" and ":sout=#display" or ":sout=#display{noaudio}"

Can anyone help me please? It must be something that causes the "[00000426] main packetizer error: cannot create packetizer output (mpga)" problem...

Yours sincerely,

Jonas

317070
Blank Cone
Blank Cone
Posts: 10
Joined: 21 Feb 2009 23:50

Re: JVLC JInternalFrame

Postby 317070 » 20 Mar 2009 17:02

Problem solved: here's a WORKING CODE with a few extra's.

Code: Select all

package mp3Player; import headFrame.PublicFrameActions; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JToggleButton; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.videolan.jvlc.Audio; import org.videolan.jvlc.JVLC; import org.videolan.jvlc.LoggerVerbosityLevel; import org.videolan.jvlc.MediaDescriptor; import org.videolan.jvlc.MediaPlayer; import org.videolan.jvlc.event.MediaPlayerListener; import settingsStorage.ConfigLoader; import settingsStorage.NoSuchParameterException; import filePackage.MP3FileInformation; public class PlayVLCVideoFrame extends JFrame{ static Canvas canvas; private static JVLC jvlc; private static MediaPlayer player; private static JToggleButton pauseButton; final private static String DEFAULTPATH = "C:/Program Files/UltraStar Deluxe/Songs/new songs/Radiohead - Creep [VIDEO]/Radiohead - Creep [VD#0].avi"; final private static int DIVISOR = 1000; final private static String DEFAULTPLUGINFOLDER = "c:\\Program Files\\VideoLAN\\VLC\\plugins"; public boolean playing = false; private static PlayVLCVideoFrame previousframe = null; public static void main(String[] arguments) throws Exception { String loc = DEFAULTPATH; PlayVLCVideoFrame vlc = new PlayVLCVideoFrame(loc,true,DEFAULTPLUGINFOLDER); } private static long starttime=-1; public PlayVLCVideoFrame(MP3FileInformation mp3) { this(mp3,false); } public PlayVLCVideoFrame(MP3FileInformation mp3,boolean sound) { this(mp3.getVideo(),sound,DEFAULTPLUGINFOLDER); this.setTitle(mp3.getArtist() +" - " + mp3.getTitle()); } String plugins; public PlayVLCVideoFrame(MP3FileInformation mp3,boolean sound, String useOtherPluginFolder) { this(mp3.getVideo(),sound,useOtherPluginFolder); this.setTitle(mp3.getArtist() +" - " + mp3.getTitle()); } public PlayVLCVideoFrame() { System.out.println("Trying to load a video, cross fingers..."); canvas = new Canvas(); this.setLayout(new BorderLayout()); this.add(canvas,BorderLayout.CENTER); JButton b1 = new JButton("set this as Lyrics-start"); b1.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { PublicFrameActions.setVideoStartTiming(getTime()); } }); this.add(b1,BorderLayout.NORTH); this.setAlwaysOnTop(true); this.addWindowListener(new WindowListener(){ @Override public void windowActivated(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowClosed(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowClosing(WindowEvent arg0) { closeFrame(); } @Override public void windowDeactivated(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowDeiconified(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowIconified(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowOpened(WindowEvent arg0) { // TODO Auto-generated method stub } }); this.setSize(200,200); //this.setResizable(false); } private static JVLC getJvlc(){ return jvlc; } private void killJvlc(){ if(player!=null){ if(player.hasVideoOutput()) player.stop(); } playing = false; jvlc = null; } private void doneBuildingFrame(){ this.pack(); this.setSize(300,300); this.setVisible(true); } public PlayVLCVideoFrame(String location, boolean sound, String pluginfolder){ this(); if(previousframe != null) { previousframe.closeFrame(); while(previousframe.playing){ try { Thread.sleep(100); } catch (InterruptedException e1) { e1.printStackTrace(); } } try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } } previousframe = this; //System.out.println("In an event (thread safe?)="+EventQueue.isDispatchThread()); File f = new File(location); System.out.println("bestaat " + location + " ? " + f.exists()); String[] args = new String[]{"-vvv","--plugin-path="+pluginfolder};//TODO: set different plugin paths while(jvlc!=null) { try{ System.out.println("Releasing jvlc"); //jvlc.release(); killJvlc(); }catch(Exception e){ e.printStackTrace(); } } String uri = "file://"+location.replace("\\", "/"); System.out.println(uri); jvlc = new JVLC(args); jvlc.setLogVerbosity(LoggerVerbosityLevel.ERROR); MediaDescriptor med = new MediaDescriptor(jvlc,uri); player = new MediaPlayer(med); final JSlider slider = new JSlider(0,(int) player.getLength()/DIVISOR,0); slider.addChangeListener(new ChangeListener(){ @Override public void stateChanged(ChangeEvent e) { setManuallyMoving(true); if(!((JSlider)e.getSource()).getValueIsAdjusting()) { int t = DIVISOR*((JSlider) e.getSource()).getValue(); setTimeSafely(t); }else{ setManuallyMoving(true); } } }); final Runnable runner = new Runnable(){ @Override public void run() { long c; while((c = getTime())!=-1 && playing){ ArrayList <ChangeListener> change = new ArrayList <ChangeListener>(); synchronized(this){ for(int i = 0; i<slider.getChangeListeners().length;i++){ change.add(slider.getChangeListeners()[i]); slider.removeChangeListener(slider.getChangeListeners()[i]); } //System.out.println("setting slider @"+c); if(!getManuallyMoving()){ slider.setValue((int) (c/DIVISOR)); slider.setToolTipText(c/1000 +"s"); slider.setMaximum((int) (player.getLength()/DIVISOR)); } for(int i = 0; i<change.size();i++){ slider.addChangeListener(change.get(i)); } try { wait(100); } catch (InterruptedException e) { e.printStackTrace(); } } } System.out.println("runner stopped"); } }; player.addListener(new MediaPlayerListener(){ @Override public void endReached(MediaPlayer arg0) { closeFrame(); } @Override public void errorOccurred(MediaPlayer arg0) { // TODO Auto-generated method stub } @Override public void paused(MediaPlayer arg0) { // TODO Auto-generated method stub } @Override public void playing(MediaPlayer arg0) { //runner.run(); } @Override public void positionChanged(MediaPlayer arg0) { // TODO Auto-generated method stub } @Override public void stopped(MediaPlayer arg0) { closeFrame(); } @Override public void timeChanged(MediaPlayer arg0, long arg1) { } }); pauseButton = new JToggleButton("Pause"); pauseButton.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { if(e.getSource() instanceof JToggleButton){ if(((JToggleButton) e.getSource()).isSelected()){ setPaused(true); pause(); }else{ setPaused(false); play(); } } } }); JPanel spanel = new JPanel(); spanel.setLayout(new FlowLayout()); spanel.add(pauseButton); spanel.add(slider); this.add(spanel,BorderLayout.SOUTH); doneBuildingFrame(); jvlc.setVideoOutput(canvas); try{ Audio audio = new Audio(jvlc); audio.setMute(!sound); player.play(); playing = true; new Thread(runner).start(); return; }catch(Exception e){ e.printStackTrace(); } } boolean pause=false; boolean isPaused(){ return pause; } void setPaused(boolean b){ pause = b; } boolean manuallymoving = false; synchronized public void setManuallyMoving(boolean b){ manuallymoving = b; } synchronized public boolean getManuallyMoving(){ return manuallymoving; } public long getTime(){ if(player!=null) { //System.out.println("Time:"+player.getTime()+"/Position:"+(player.getPosition()*player.getLength())); return player.getTime(); } return (Long.MIN_VALUE); } public long getLength(){ return player.getLength(); } public void setTime(long time){ player.setTime(time); starttime=-1; } public void setPosition(float position){ if(position <0 || position >1)return; player.setPosition(position); } public float getPosition(){ return player.getPosition(); } public void pause(){ player.pause(); starttime=-1; } public void play(){ player.play(); } public float getFPS(){ return player.getFPS(); } boolean alreadyclosing = false; public void closeFrame(){ starttime=-1; if(alreadyclosing)return; alreadyclosing=true; System.out.println("closing window"); try{ if(getJvlc()!=null){} //getJvlc().release(); }catch(Exception e){ System.out.println("problem destroying"); }finally{ System.out.println("killing JVLC"); killJvlc(); } this.setVisible(false); this.dispose(); } public void setTimeSafely(long t) { // TODO Auto-generated method stub setManuallyMoving(true); if(t<getLength() && t>0) { pause(); while(getTime()!=t) setTime(t); System.out.println("setting time to "+ t + " s. Paused? "+ isPaused()); if(!isPaused()){ play(); }else{ pause(); } setManuallyMoving(false); }else{ System.err.println("bad t timing!"); } } public void setTimeFast(long t) { // TODO Auto-generated method stub if(t<getLength() && t>0) { while(getTime()!=t) setTime(t); System.out.println("setting time to "+ t + " s. Paused? "+ isPaused()); }else{ System.err.println("bad t timing! " + t); } } public void startplaying() { // TODO Auto-generated method stub } //this method should be able to detect the time with a resolution of more than .2s public long getTimeAccurately(){ if(starttime>0){ return System.currentTimeMillis()-starttime; }else{ detectStartTime(); return getTimeAccurately(); } } //this method can take up to .2s public void detectStartTime(){ System.out.println("Detecting Start Time"); long t = getTime(); long c; long a; while(t>=(a=getTime()) & (c=System.currentTimeMillis())!=0){ } starttime = c-a; System.out.println("detected a starttime at "+starttime+".Thats "+(System.currentTimeMillis()-starttime) + "ms ago."); } }

s.naujoks
New Cone
New Cone
Posts: 3
Joined: 30 Jul 2008 18:31

Re: JVLC JInternalFrame

Postby s.naujoks » 14 Jun 2009 20:05

where can I find the classes Mp3FileInformation and ConfigLoader? I googled a long time. Can you help me please?

317070
Blank Cone
Blank Cone
Posts: 10
Joined: 21 Feb 2009 23:50

Re: JVLC JInternalFrame

Postby 317070 » 01 Oct 2009 20:36

These are files I used for my project. The Configloader and NoSuchParameterException are not even used in that class, so they can be deleted without problems. The MP3FileInformation basically has the information of a certain file. MP3.getTitle() gives the title in String format, getArtist() is similar (but these are not important). MP3.getVideo() returns the path of the file you'd want to play, in String format. I can confirm (through testing) that this class never crashes Java. The problem had something to do with a EventHandler, if I remember correctly, and should be commented out in the code. But it's been a long time since I wrote that :D .

So, just stay off fancy things, and test EVERY TIME you add something, some methods of JVLC are broke. It's a pita to test afterwards which one :(

P.S. If you do get crashes, I'd be happy to post my latest version of this code.


Return to “VLC media player for Windows Troubleshooting”

Who is online

Users browsing this forum: No registered users and 64 guests