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.
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
// 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");
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.
Thank you so much for replying fast. We have installed a VLC player and the OS is Windows 10.
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by: java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: mygame.VLCMediaPlayer
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.