rlm@3: package com.aurellem.capture; rlm@3: rlm@3: import java.io.File; rlm@3: import java.io.IOException; rlm@12: import java.util.concurrent.Callable; rlm@3: rlm@12: import com.aurellem.capture.audio.MultiListener; rlm@12: import com.aurellem.capture.audio.WaveFileWriter; rlm@9: import com.aurellem.capture.video.AVIVideoRecorder; rlm@10: import com.aurellem.capture.video.AbstractVideoRecorder; rlm@39: import com.aurellem.capture.video.FileVideoRecorder; rlm@10: import com.aurellem.capture.video.XuggleVideoRecorder; rlm@3: import com.jme3.app.Application; rlm@12: import com.jme3.audio.AudioRenderer; rlm@12: import com.jme3.renderer.ViewPort; rlm@12: import com.jme3.scene.Spatial; rlm@12: import com.jme3.system.AppSettings; rlm@3: rlm@3: public class Capture { rlm@3: rlm@12: public static void captureVideo(final Application app, final File file) throws IOException{ rlm@12: rlm@12: final AbstractVideoRecorder videoRecorder; rlm@10: // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way rlm@10: // except for ease of installation. The excellent work by Werner Randelshofer rlm@10: // is used as a fallback option. Please visit http://www.xuggle.com/ to learn rlm@10: // how to set up the XuggleVideoRecorder. rlm@12: rlm@12: if (file.getCanonicalPath().endsWith(".avi")){ rlm@12: videoRecorder = new AVIVideoRecorder(file);} rlm@39: else if (file.isDirectory()){ rlm@39: videoRecorder = new FileVideoRecorder(file);} rlm@12: else { videoRecorder = new XuggleVideoRecorder(file);} rlm@12: rlm@12: Callable thunk = new Callable(){ rlm@12: public Object call(){ rlm@12: rlm@12: ViewPort viewPort = rlm@12: app.getRenderManager() rlm@12: .createPostView("aurellem record", app.getCamera()); rlm@12: rlm@12: viewPort.setClearFlags(false, false, false); rlm@12: rlm@12: // get GUI node stuff rlm@12: for (Spatial s : app.getGuiViewPort().getScenes()){ rlm@12: viewPort.attachScene(s); rlm@12: } rlm@12: rlm@12: app.getStateManager().attach(videoRecorder); rlm@12: viewPort.addProcessor(videoRecorder); rlm@12: return null; rlm@12: } rlm@12: }; rlm@12: app.enqueue(thunk); rlm@12: } rlm@12: rlm@12: rlm@12: public static void captureAudio(final Application app, final File file) throws IOException{ rlm@12: AppSettings settings = new AppSettings(true); rlm@12: settings.setAudioRenderer("Send"); rlm@12: app.setSettings(settings); rlm@24: final WaveFileWriter writer = new WaveFileWriter(file); rlm@12: rlm@12: Callable thunk = new Callable(){ rlm@12: public Object call(){ rlm@12: AudioRenderer ar = app.getAudioRenderer(); rlm@12: if (ar instanceof MultiListener){ rlm@12: MultiListener ml = (MultiListener)ar; rlm@24: ml.registerSoundProcessor(writer); rlm@12: } rlm@12: return null; rlm@12: } rlm@12: }; rlm@10: rlm@12: app.enqueue(thunk); rlm@12: } rlm@12: rlm@3: }