My task is to play multiple videos with a linked time scrubber in a grid, and I've gotten it to work (WITH VLCJ NOT VLCJ-PRO), but it is VERY finicky.
So I decided to give VLCJ-Pro a try, but I'm getting an error on the first line.
22:25:25.614 [main] INFO u.c.c.vlcj.discovery.NativeDiscovery - Discovery
found libvlc at 'D:\VLC'
C:\Users\trans\AppData\Local\NetBeans\Cache\8.2\executor-
snippets\run.xml:53: Java returned: -57005
BUILD FAILED (total time: 0 seconds)
VLCJ-Pro is supposed to help with VLCJ's multi-video problems (native library crashes happen alot). So I figured I'd see if it helped with stability, but I can't even get it to run.
VLCJ-Pro Download Location
Here is my entire code I'm using to test the library. I'm using Netbeans as my IDE and I've added ALL the JAR libraries in the example code.
If you have any experience with VLCJ-Pro I would greatly appreciate any feedback on how I'm going wrong.
package vlcjprodemo;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.version.LibVlcVersion;
import uk.co.caprica.vlcjpro.client.player.OutOfProcessMediaPlayer;
import uk.co.caprica.vlcjpro.client.player.OutOfProcessMediaPlayerComponent;
import uk.co.caprica.vlcjpro.client.player.OutOfProcessMediaPlayerComponentFactory;
public class VLCJProDemo {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
new NativeDiscovery().discover();
LibVlcVersion.getVersion();
//CRASHES HERE
OutOfProcessMediaPlayerComponentFactory theFactory = new OutOfProcessMediaPlayerComponentFactory();
OutOfProcessMediaPlayerComponent theComponent = theFactory.newOutOfProcessMediaPlayerComponent();
Canvas theVideoCanvas = new Canvas();
theVideoCanvas.setFocusable(true);
theVideoCanvas.setSize(new Dimension(1920, 1080));
theVideoCanvas.setLocation(0, 0);
theComponent.setVideoSurface(theVideoCanvas);
OutOfProcessMediaPlayer theMediaPlayer = theComponent.mediaPlayer();
theMediaPlayer.setRepeat(true);
JFrame mainFrame = new JFrame();
mainFrame.setLayout(new BorderLayout());
mainFrame.setBackground(Color.black);
mainFrame.setMaximumSize(new Dimension(1920, 1080));
mainFrame.setPreferredSize(new Dimension(1920, 1080));
mainFrame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainFrame.add(theVideoCanvas);
mainFrame.pack();
mainFrame.setVisible(true);
theMediaPlayer.playMedia("horse.avi");
}
}
Probably you are trying to use a trial/demo version of vlcj-pro that has expired.
If so, you need to wait until a new trial version is published.
Related
I've been making progress on my Java application that loads and displays X3D models. However, now, I'm getting the following error
Exception in thread "main" org.web3d.x3d.sai.NotSupportedException: Default Browser implementation cannot create browser reference
at org.web3d.x3d.sai.DefaultBrowserImpl.createComponent(DefaultBrowserImpl.java:53)
at org.web3d.x3d.sai.BrowserFactory.createX3DComponent(BrowserFactory.java:185)
at xj3dtest.Xj3DTest.<init>(Xj3DTest.java:42)
at xj3dtest.Xj3DTest.main(Xj3DTest.java:56)
C:\Users\matt\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
My Java code is
package xj3dtest;
import java.awt.BorderLayout;
import java.awt.Container;
import static java.lang.Boolean.TRUE;
import javax.swing.JFrame;
import org.web3d.x3d.sai.Browser;
import org.web3d.x3d.sai.BrowserFactory;
import org.web3d.x3d.sai.X3DComponent;
import org.web3d.x3d.sai.X3DScene;
import java.util.HashMap;
public class Xj3DTest extends JFrame {
public Xj3DTest(String title) {
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Setup browser parameters
HashMap requestedParameters=new HashMap();
requestedParameters.put("Antialiased",TRUE);
requestedParameters.put("TextureQuality","medium");
requestedParameters.put("PrimitiveQuality","medium");
requestedParameters.put("Xj3D_InterfaceType","SWING");
requestedParameters.put("Xj3D_NavbarShown",TRUE);
requestedParameters.put("Xj3D_NavbarPosition","TOP");
requestedParameters.put("Xj3D_LocationShown",TRUE);
requestedParameters.put("Xj3D_LocationPosition","TOP");
requestedParameters.put("Xj3D_LocationReadOnly",TRUE);
requestedParameters.put("Xj3D_ShowConsole",TRUE);
requestedParameters.put("Xj3D_OpenButtonShown",TRUE);
requestedParameters.put("Xj3D_ReloadButtonShown",TRUE);
requestedParameters.put("Xj3D_StatusBarShown",TRUE);
requestedParameters.put("Xj3D_FPSShown",TRUE);
requestedParameters.put("Xj3D_ContentDirectory","CurrentDirectory");
requestedParameters.put("Xj3D_AntialiasingQuality","low");
requestedParameters.put("Xj3D_Culling_Mode", "frustum");
System.setProperty("x3d.sai.factory.class", "org.xj3d.ui.awt.browser.ogl.X3DOGLBrowserFactoryImpl");
X3DComponent x3dComponent = BrowserFactory.createX3DComponent(requestedParameters);
Browser browser = x3dComponent.getBrowser();
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add((javax.swing.JPanel)x3dComponent, BorderLayout.CENTER);
X3DScene scene = browser.createX3DFromURL(new String[] {"test.x3d"});
browser.replaceWorld(scene);
}
public static void main(String[] args) {
Xj3DTest frame = new Xj3DTest("Xj3D test");
frame.setSize(640, 480);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
The Jars that I'm using are
aviatrix3d-all_3.1.0-nps.jar
commons-compress-1.10.jar
dis-enums.jar
geoapi-nogenerics-2.1.0.jar
gluegen-rt-natives-linux-amd64.jar
gluegen-rt-natives-macosx-universal.jar
gluegen-rt-natives-windows-amd64.jar
gluegen-rt-natives-windows-i586.jar
gluegen-rt.jar
gnu-regexp-1.0.8.jar
gt2-main-2.4.4.jar
gt2-metadata-2.4.4.jar
gt2-referencing-2.4.4.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
httpclient.jar
imageloader_1.1.0.jar
j3d-org-all_3.0.0-nps.jar
jai_codec.jar
jai_core.jar
jgeom-core.jar
jhall.jar
jmf.jar
joal-natives-linux-amd64.jar
joal-natives-macosx-universal.jar
joal-natives-windows-amd64.jar
joal-natives-windows-i586.jar
joal.jar
jogl-all-natives-linux-amd64.jar
jogl-all-natives-macosx-universal.jar
jogl-all-natives-windows-amd64.jar
jogl-all-natives-windows-i586.jar
jogl-all.jar
js.jar
jsr108-0.01.jar
odejava-jni.jar
odejava.jar
open-dis_4.08.jar
openmali.jar
smack.jar
smackx.jar
toxiclibscore.jar
uri.jar
vecmath.jar
vlc_uri.jar
xj3d-sai.jar
I have Google Chrome as my default browser and I'm in dire need of help because it seems like I've been stuck on the same problem for ages. Thanks.
Good day colleagues!
I had several trouble using VLCJ and other Java media API-s.
1) I'd add a simple *.srt file to my EmbeddedMediaPlayerCompononent, bot how is this possible?
2) Also, how can I configurate the VLC lib in an x64 Windows OS?
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files (x86)\\VideoLAN\\VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(),libVlc.class);
This not works well.
3) How could I add basic operation interface to my EmbeddedMediaPlayerCompononent like pause/play button?
Thank you, best regards! :)
My "VideoPlayer" class
package GUI.MediaPlayer;
import java.awt.BorderLayout;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import StreamBean.UIBean;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
public class VideoPlayer extends JFrame{
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
public VideoPlayer(String videoURL) {
String os = System.getProperty("os.name").toLowerCase();
if(os.startsWith("win")){
String registrytype = System.getProperty("sun.arch.data.model");
System.out.println("a rendszered : " +os+" - " +registrytype+ " bites");
if(registrytype.contains("32")){
//Windows 32 bites verzió
System.out.println("Belépett a 32-be");
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files\\VideoLAN\\VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
}else if(registrytype.contains("64")){
//Windows 64 bites verzió
System.out.println("Belépett a 64-be");
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files (x86)\\VideoLAN\\VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
}else{
JOptionPane.showMessageDialog(null, "Kérem előbb telepítse a VLC lejátszót.");
}
}
if(os.startsWith("mac")){
//Mac OSX kiadáshoz
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "/Applications/VLC.app/Contents/MacOS/lib/");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
}
this.setTitle("Aktuális videó");
this.setLayout(new BorderLayout());
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
this.add(mediaPlayerComponent,BorderLayout.CENTER);
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
//set the Jframe - this - resolution to the screen resoltuion
new UIBean().setWindowSize(this);
this.setVisible(true);
mediaPlayerComponent.getMediaPlayer().playMedia(videoURL);
}
}
To set an external subtitle file:
mediaPlayerComponent.getMediaPlayer().setSubTitleFile("whatever.srt");
How you add a pause/play button is entirely up to you, it requires standard Swing code that is not particular to vlcj. You add buttons to your user interface, and link those buttons up with the media player by using event listeners. For example, this is one way:
JButton playButton = new JButton("Play/Pause");
playButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
mediaPlayerComponent.getMediaPlayer.pause();
}
});
There are numerous reasons why the native library might not be found, but NativeLibrary.addSearchPath(...) certainly does work. You have to be sure you match the CPU architectures of your JVM and your VLC installation (32-bit JVM requires 32-bit VLC, 64-bit JVM requires 64-bit VLC). In most cases you should just use:
new NativeDiscovery().discover();
There are a whole bunch of step-by-step tutorials at http://capricasoftware.co.uk/#/projects/vlcj/tutorial
Focusing on the "basic operation interface" aspect of your question, note that EmbeddedMediaPlayerComponent extends Panel, an AWT component. Accordingly, the VLCJ overlay example shown here overrides paint(). This related, stand-alone example illustrates hit testing in such context.
I am wanting to make a simple java applicaiton to play video. I want it to play mpeg4 and mov formats in particular. JMF is what I started with and I have a lovely working example. However, there is no support for mov or mpeg4 formats. I've looked at Xuggler but can't see a SIMPLE way to get it working. VLCJ seemed easy - I downloaded the jar files and attached them to my project (vlcj-2.1.0.jar, jna-3.4.0.jar, platform-3.4.0.jar, vlcj-2.1.0.jar)). I got the sample code and adapted it (below). But when I run the code, I get a java.lang.NullPointerException exception. I've tried adjusting the number and direciton of the slashes (forward and backward) in the filename. Nothing seems to work. Please could you help???
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JFileChooser;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import java.lang.Object;
import uk.co.caprica.vlcj.mrl.FileMrl;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
public class TestPlayer {
private final JFrame frame;
private EmbeddedMediaPlayerComponent mediaPlayer;
public static void loadLibs(){
NativeLibrary.addSearchPath(
RuntimeUtil.getLibVlcLibraryName(), "C:/Program Files/VideoLAN/VLC/"
);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
}
public static void main(final String[] args){
loadLibs();
final String mrl = "file://C:/Test.mov";
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new TestPlayer().run(mrl);
}
});
}
public TestPlayer(){
frame = new JFrame("test VLCJ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(100,100);
frame.setSize(600,400);
frame.setVisible(true);
}
private void run(String mrl){
System.out.println(mrl);
try{
mediaPlayer.getMediaPlayer().playMedia(mrl);
}catch(Exception e){
System.err.println(e.toString());
}
}
}
I'm using VLC version 2.0.2 and VLCJ 2.1.0 sources and JDK 1.7 on windows 32 bit. I hope it's something simple...
It looks like you are using mediaPlayerwithout ever initializing it, thus causing a NullPointerException in run().
Try initializing it in your constructor.
I have a Java program which I'd like to call from a Jython program. I'd like to be able to have the two interface with one another and had hoped to call the Java program from Jython with an action listener as a parameter, but so far I have had no luck.
Jython code:
import sys
sys.path.append("sgJython.jar")
from java.awt.event import ActionListener
from java.awt.event import ActionEvent
from sg.gui import MainGui
class MyListener(ActionListener):
def ActionPerformed(e):
print("gotit")
ml = MyListener()
MainGui(ml)
Java code:
package sg;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class MainGui
{
public MainGui(ActionListener listener)
{
top = new JFrame();
top.setBounds(300, 300, 600, 300);
JButton doneButton = new JButton("Done");
doneButton.addActionListener(listener);
top.add(doneButton)
}
}
Is there some other way of doing this? If not, is there a better way to go about integrating Java and Python into a single application, or is that not a good thing to do?
The way it is already works, you just have to fix the actionPerformed method, which has a wrong signature and which does not declare the self parameter.
class MyListener(ActionListener):
def actionPerformed(self, e):
print("gotit")
In your Java code, you missed a couple of semicolons and since you are not displaying the frame it will not be visible unless you explicitly ask it from your Jython code. So I changed it a bit for testing purposes:
public class MainGui {
private JFrame top;
public MainGui(ActionListener listener) {
top = new JFrame();
top.setBounds(300, 300, 600, 300);
JButton doneButton = new JButton("Done");
doneButton.addActionListener(listener);
top.add(doneButton);
top.pack();
top.setVisible(true);
}
}
I did the Java code in a Java Project in Eclipse and the Python code in PyDev project in Eclipse, then I ran the Python script and it worked like a charm.
Is there any way to force a user to give his/her input via overwriting certain characters.
i.e.:
First screen:
Amount: ___.__
Second:
Amount: 1__.__
... goes like this ...
Finally:
Amount: 1200.50
But i want to be sure that numbers will be printed as soon as user presses the keyboard.
Thanks in advance.
p.s.: OS is MS Windows 9x/XP/Vista/7. And the application is for console.
MaskFormatter mf1 = new MaskFormatter("#####.##");
mf1.setPlaceholderCharacter('_');
JFormattedTextField ftf1 = new JFormattedTextField(mf1);
Here's the full code
import java.awt.Container;
import java.text.ParseException;
import javax.swing.BoxLayout;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.text.MaskFormatter;
public class Test {
public static void main(String args[]) throws ParseException {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = f.getContentPane();
content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
MaskFormatter mf1 = new MaskFormatter("######.###");
mf1.setPlaceholderCharacter('_');
JFormattedTextField ftf1 = new JFormattedTextField(mf1);
content.add(ftf1);
f.setSize(300, 100);
f.setVisible(true);
}
}
You don't say what OS you're on. For performing advanced input terminal work, this could be important.
You could spend some time implementing such a solution in Java by capturing keystrokes yourself, regenerating the input line etc. On the other hand, have you looked at JLine ?