Whilst looking for a way to draw a video onto a texture using jMonkey, I couldn’t find a working example, so after a bit of work I managed to come up with something relatively simple that works and shows a video painted onto a texture.
There are problems - as listed below - but it will at least give you a head start to work with something.
Caveats
VLCJ is GPL - probably going to restrict you if you don’t want to publish your code as GPL.
VLC Player must be installed on the client machine - or alternatively you can ship the required files with your built project.
The 64bit version of VLC player is a bit “dodgy” - It is recommended that you use the 32bit version, and thus compile against the 32bit version of java because wont work cross-platform.
Probably a good idea to read through the tutorials as well while you’re in a reading mood
Useage:
// the path to your video file - network paths work too.
String filePath = "\\\\NSA310\\video\\Movies\\Shrek 2 (2004).avi";
// the width and height of the movie...
final int width = 704, height = 384;
VLCMediaPlayer vlc = new VLCMediaPlayer(filePath, width, height);
// a quad sized in the correct proportion to the video...
Quad quad = new Quad(7.04f, 3.84f);
Geometry geom = new Geometry("quad", quad);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", vlc.getTexture());
geom.setMaterial(mat);
rootNode.attachChild(geom);
vlc.play();
Support for playing media, especially video media, is generally poor on the Java platform. The Java Media Framework can be used to play some media, but it seems to be a neglected framework and has not been updated to play media encoded with modern codecs. JavaFX also provides the ability to play some media, but not all. In addition to playing media it is often desirable to be able to publish and consume streams of media across the network or the Internet and this too is not well supported by existing Java frameworks.
For these reasons, the usual solution is to use a native media framework and bind to it using native libraries by using the Java Native Interface (JNI), or the Java Native API (JNA) to simplify JNI.
There are a number of different native media players that could be used in this way, two such widely used media players are VLC and mplayer. The vlcj project was created to integrate VLC into Java applications.
@jayfella
Thank you so much for replying fast. We have installed a VLC player and the OS is Windows 10.
onStartScreen
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at de.lessvoid.nifty.NiftyMethodInvoker.callMethod(NiftyMethodInvoker.java:157)
at de.lessvoid.nifty.NiftyMethodInvoker.performInvoke(NiftyMethodInvoker.java:115)
at de.lessvoid.nifty.Nifty$DelayedMethodInvoke.perform(Nifty.java:1481)
at de.lessvoid.nifty.Nifty.invokeMethods(Nifty.java:1457)
at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:439)
at de.lessvoid.nifty.Nifty.access$1600(Nifty.java:87)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1727)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1665)
at com.jme3.niftygui.InputSystemJme.handleMouseEvent(InputSystemJme.java:123)
at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(InputSystemJme.java:231)
at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:295)
at de.lessvoid.nifty.Nifty.update(Nifty.java:368)
at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:112)
at com.jme3.input.InputManager.processQueue(InputManager.java:850)
at com.jme3.input.InputManager.update(InputManager.java:914)
at com.jme3.app.LegacyApplication.update(LegacyApplication.java:725)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:227)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: mygame.VLCMediaPlayer
at mygame.MyStartScreen.controlGame(MyStartScreen.java:157)
Hi @jayfella, we tried the solutions provided in the stackoverflow link, but it still doesn’t work.
In our source code…
In this picture, when we hover the “getMediaPlayer().” and there’s a list of possible methods to use like play() which opens up a description popup, and there’s no error when we use that.
However, in this picture, when we click on playMedia(String), there’s no java doc description popup which makes us think the function may no longer exist and that may be why we’re unable to run the program?
For what its worth, I also did this (but one year later, so I should have used the search function on the forum before attempting it). I haven’t used it either since then, but maybe it works out of the box:
If you try to mix 32bit/64bit VLC player/java it won’t work - for me it spits out a huge descriptive error log.
If memory serves - and this was 4 years ago - I think version 3 of VLCJ had issues with the 64bit player. I’m not sure if version 4 resolves this but it doesn’t seem backwards compatible - as expected - since the major version changed.
It may be that upgrading to VLCJ 4 makes all of this a non-isse.
HI,I have a Ultra Video(2560*1440)
I try to load video to the TestVlcPlayer4.java code.
I only modify width(2560) and height(1440).
But the video cannot play in this code.
Do you have VLC player 64bit installed? Did you set the path to the video? Does the video play in VLC player? Have you tried a different video/format? What does it say in the logs?