annotate src/com/aurellem/capture/Capture.java @ 26:95648b0c12bc

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