view src/com/aurellem/capture/Capture.java @ 53:3dc1f15e1e13

going to write main documentation
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Dec 2011 13:54:47 -0600
parents 121b6d7e4d3f
children 6484a820e27d
line wrap: on
line source
1 package com.aurellem.capture;
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.concurrent.Callable;
7 import com.aurellem.capture.audio.MultiListener;
8 import com.aurellem.capture.audio.WaveFileWriter;
9 import com.aurellem.capture.video.AVIVideoRecorder;
10 import com.aurellem.capture.video.AbstractVideoRecorder;
11 import com.aurellem.capture.video.FileVideoRecorder;
12 import com.aurellem.capture.video.XuggleVideoRecorder;
13 import com.jme3.app.Application;
14 import com.jme3.audio.AudioRenderer;
15 import com.jme3.renderer.ViewPort;
16 import com.jme3.scene.Spatial;
17 import com.jme3.system.AppSettings;
18 import com.jme3.system.JmeSystem;
20 /**
21 *
22 * @author Robert McIntyre
23 *
24 */
26 public class Capture {
28 public static void captureVideo(final Application app, final File file) throws IOException{
30 final AbstractVideoRecorder videoRecorder;
31 // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way
32 // except for ease of installation. The excellent work by Werner Randelshofer
33 // is used as a fallback option. Please visit http://www.xuggle.com/ to learn
34 // how to set up the XuggleVideoRecorder.
36 if (file.getCanonicalPath().endsWith(".avi")){
37 videoRecorder = new AVIVideoRecorder(file);}
38 else if (file.isDirectory()){
39 videoRecorder = new FileVideoRecorder(file);}
40 else { videoRecorder = new XuggleVideoRecorder(file);}
42 Callable<Object> thunk = new Callable<Object>(){
43 public Object call(){
45 ViewPort viewPort =
46 app.getRenderManager()
47 .createPostView("aurellem video record", app.getCamera());
49 viewPort.setClearFlags(false, false, false);
51 // get GUI node stuff
52 for (Spatial s : app.getGuiViewPort().getScenes()){
53 viewPort.attachScene(s);
54 }
56 app.getStateManager().attach(videoRecorder);
57 viewPort.addProcessor(videoRecorder);
58 return null;
59 }
60 };
61 app.enqueue(thunk);
62 }
65 public static void captureAudio(final Application app, final File file) throws IOException{
66 AppSettings settings = null;
67 if (app.getContext() != null){settings = app.getContext().getSettings();}
68 if (settings == null){settings = new AppSettings(true);}
69 settings.setAudioRenderer("Send");
70 app.setSettings(settings);
72 JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
75 final WaveFileWriter writer = new WaveFileWriter(file);
77 Callable<Object> thunk = new Callable<Object>(){
78 public Object call(){
79 AudioRenderer ar = app.getAudioRenderer();
80 if (ar instanceof MultiListener){
81 MultiListener ml = (MultiListener)ar;
82 ml.registerSoundProcessor(writer);
83 }
84 return null;
85 }
86 };
88 app.enqueue(thunk);
89 }
90 }