view src/com/aurellem/capture/Capture.java @ 23:b643413c3aba

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