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