view 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
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.JmeSystem;
19 public class Capture {
21 public static void captureVideo(final Application app, final File file) throws IOException{
23 final AbstractVideoRecorder videoRecorder;
24 // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way
25 // except for ease of installation. The excellent work by Werner Randelshofer
26 // is used as a fallback option. Please visit http://www.xuggle.com/ to learn
27 // how to set up the XuggleVideoRecorder.
29 if (file.getCanonicalPath().endsWith(".avi")){
30 videoRecorder = new AVIVideoRecorder(file);}
31 else if (file.isDirectory()){
32 videoRecorder = new FileVideoRecorder(file);}
33 else { videoRecorder = new XuggleVideoRecorder(file);}
35 Callable<Object> thunk = new Callable<Object>(){
36 public Object call(){
38 ViewPort viewPort =
39 app.getRenderManager()
40 .createPostView("aurellem record", app.getCamera());
42 viewPort.setClearFlags(false, false, false);
44 // get GUI node stuff
45 for (Spatial s : app.getGuiViewPort().getScenes()){
46 viewPort.attachScene(s);
47 }
49 app.getStateManager().attach(videoRecorder);
50 viewPort.addProcessor(videoRecorder);
51 return null;
52 }
53 };
54 app.enqueue(thunk);
55 }
58 public static void captureAudio(final Application app, final File file) throws IOException{
60 JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
62 final WaveFileWriter writer = new WaveFileWriter(file);
64 Callable<Object> thunk = new Callable<Object>(){
65 public Object call(){
66 AudioRenderer ar = app.getAudioRenderer();
67 if (ar instanceof MultiListener){
68 MultiListener ml = (MultiListener)ar;
69 ml.registerSoundProcessor(writer);
70 }
71 return null;
72 }
73 };
75 app.enqueue(thunk);
76 }
78 }