annotate src/com/aurellem/capture/Capture.java @ 44:388f9d062012

adapting to execellent new jmeSystem changes
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Dec 2011 12:18:55 -0600
parents 784a3f4e6202
children 121b6d7e4d3f
rev   line source
rlm@3 1 package com.aurellem.capture;
rlm@3 2
rlm@3 3 import java.io.File;
rlm@3 4 import java.io.IOException;
rlm@12 5 import java.util.concurrent.Callable;
rlm@3 6
rlm@12 7 import com.aurellem.capture.audio.MultiListener;
rlm@12 8 import com.aurellem.capture.audio.WaveFileWriter;
rlm@9 9 import com.aurellem.capture.video.AVIVideoRecorder;
rlm@10 10 import com.aurellem.capture.video.AbstractVideoRecorder;
rlm@39 11 import com.aurellem.capture.video.FileVideoRecorder;
rlm@10 12 import com.aurellem.capture.video.XuggleVideoRecorder;
rlm@3 13 import com.jme3.app.Application;
rlm@12 14 import com.jme3.audio.AudioRenderer;
rlm@12 15 import com.jme3.renderer.ViewPort;
rlm@12 16 import com.jme3.scene.Spatial;
rlm@44 17 import com.jme3.system.JmeSystem;
rlm@3 18
rlm@3 19 public class Capture {
rlm@3 20
rlm@12 21 public static void captureVideo(final Application app, final File file) throws IOException{
rlm@12 22
rlm@12 23 final AbstractVideoRecorder videoRecorder;
rlm@10 24 // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way
rlm@10 25 // except for ease of installation. The excellent work by Werner Randelshofer
rlm@10 26 // is used as a fallback option. Please visit http://www.xuggle.com/ to learn
rlm@10 27 // how to set up the XuggleVideoRecorder.
rlm@12 28
rlm@12 29 if (file.getCanonicalPath().endsWith(".avi")){
rlm@12 30 videoRecorder = new AVIVideoRecorder(file);}
rlm@39 31 else if (file.isDirectory()){
rlm@39 32 videoRecorder = new FileVideoRecorder(file);}
rlm@12 33 else { videoRecorder = new XuggleVideoRecorder(file);}
rlm@12 34
rlm@12 35 Callable<Object> thunk = new Callable<Object>(){
rlm@12 36 public Object call(){
rlm@12 37
rlm@12 38 ViewPort viewPort =
rlm@12 39 app.getRenderManager()
rlm@12 40 .createPostView("aurellem record", app.getCamera());
rlm@12 41
rlm@12 42 viewPort.setClearFlags(false, false, false);
rlm@12 43
rlm@12 44 // get GUI node stuff
rlm@12 45 for (Spatial s : app.getGuiViewPort().getScenes()){
rlm@12 46 viewPort.attachScene(s);
rlm@12 47 }
rlm@12 48
rlm@12 49 app.getStateManager().attach(videoRecorder);
rlm@12 50 viewPort.addProcessor(videoRecorder);
rlm@12 51 return null;
rlm@12 52 }
rlm@12 53 };
rlm@12 54 app.enqueue(thunk);
rlm@12 55 }
rlm@12 56
rlm@12 57
rlm@12 58 public static void captureAudio(final Application app, final File file) throws IOException{
rlm@44 59
rlm@44 60 JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
rlm@44 61
rlm@24 62 final WaveFileWriter writer = new WaveFileWriter(file);
rlm@12 63
rlm@12 64 Callable<Object> thunk = new Callable<Object>(){
rlm@12 65 public Object call(){
rlm@12 66 AudioRenderer ar = app.getAudioRenderer();
rlm@12 67 if (ar instanceof MultiListener){
rlm@12 68 MultiListener ml = (MultiListener)ar;
rlm@24 69 ml.registerSoundProcessor(writer);
rlm@12 70 }
rlm@12 71 return null;
rlm@12 72 }
rlm@12 73 };
rlm@10 74
rlm@12 75 app.enqueue(thunk);
rlm@12 76 }
rlm@12 77
rlm@3 78 }