view src/com/aurellem/capture/Capture.java @ 49:121b6d7e4d3f

more friendly AppSettings handling
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Dec 2011 13:22:27 -0600
parents 388f9d062012
children 3dc1f15e1e13
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 public class Capture {
22 public static void captureVideo(final Application app, final File file) throws IOException{
24 final AbstractVideoRecorder videoRecorder;
25 // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way
26 // except for ease of installation. The excellent work by Werner Randelshofer
27 // is used as a fallback option. Please visit http://www.xuggle.com/ to learn
28 // how to set up the XuggleVideoRecorder.
30 if (file.getCanonicalPath().endsWith(".avi")){
31 videoRecorder = new AVIVideoRecorder(file);}
32 else if (file.isDirectory()){
33 videoRecorder = new FileVideoRecorder(file);}
34 else { videoRecorder = new XuggleVideoRecorder(file);}
36 Callable<Object> thunk = new Callable<Object>(){
37 public Object call(){
39 ViewPort viewPort =
40 app.getRenderManager()
41 .createPostView("aurellem video record", app.getCamera());
43 viewPort.setClearFlags(false, false, false);
45 // get GUI node stuff
46 for (Spatial s : app.getGuiViewPort().getScenes()){
47 viewPort.attachScene(s);
48 }
50 app.getStateManager().attach(videoRecorder);
51 viewPort.addProcessor(videoRecorder);
52 return null;
53 }
54 };
55 app.enqueue(thunk);
56 }
59 public static void captureAudio(final Application app, final File file) throws IOException{
60 AppSettings settings = null;
61 if (app.getContext() != null){settings = app.getContext().getSettings();}
62 if (settings == null){settings = new AppSettings(true);}
63 settings.setAudioRenderer("Send");
64 app.setSettings(settings);
66 JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
69 final WaveFileWriter writer = new WaveFileWriter(file);
71 Callable<Object> thunk = new Callable<Object>(){
72 public Object call(){
73 AudioRenderer ar = app.getAudioRenderer();
74 if (ar instanceof MultiListener){
75 MultiListener ml = (MultiListener)ar;
76 ml.registerSoundProcessor(writer);
77 }
78 return null;
79 }
80 };
82 app.enqueue(thunk);
83 }
84 }