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"); mat.setTexture("ColorMap", vlc.getTexture()); geom.setMaterial(mat); rootNode.attachChild(geom); vlc.play();
Feel free to use, abuse, etc…
And here’s some screenshots of it working: