diff src/com/aurellem/capture/Capture.java @ 12:d10f4d4ff15a

going to improve documentation
author Robert McIntyre <rlm@mit.edu>
date Thu, 27 Oct 2011 21:07:50 -0700
parents 8a6b1684f536
children 5f616cc420dd
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/Capture.java	Thu Oct 27 02:27:02 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/Capture.java	Thu Oct 27 21:07:50 2011 -0700
     1.3 @@ -2,34 +2,73 @@
     1.4  
     1.5  import java.io.File;
     1.6  import java.io.IOException;
     1.7 +import java.util.concurrent.Callable;
     1.8  
     1.9 +import com.aurellem.capture.audio.MultiListener;
    1.10 +import com.aurellem.capture.audio.WaveFileWriter;
    1.11  import com.aurellem.capture.video.AVIVideoRecorder;
    1.12  import com.aurellem.capture.video.AbstractVideoRecorder;
    1.13  import com.aurellem.capture.video.XuggleVideoRecorder;
    1.14  import com.jme3.app.Application;
    1.15 -import com.jme3.math.ColorRGBA;
    1.16 +import com.jme3.audio.AudioRenderer;
    1.17 +import com.jme3.renderer.ViewPort;
    1.18 +import com.jme3.scene.Spatial;
    1.19 +import com.jme3.system.AppSettings;
    1.20  
    1.21  public class Capture {
    1.22  
    1.23 -	public static void SimpleCaptureVideo(Application app, File file) throws IOException{
    1.24 -		app.getViewPort().setClearFlags(true, true, true);
    1.25 -		// this prevents pixels from staying in the render buffer between frames
    1.26 -		// and messing the video up.  It's not a problem since Black is the default, and this 
    1.27 -		// can be overridden by user code.
    1.28 -		app.getViewPort().setBackgroundColor(ColorRGBA.Black);
    1.29 -		
    1.30 +	public static void captureVideo(final Application app, final File file) throws IOException{
    1.31 +
    1.32 +		final AbstractVideoRecorder videoRecorder;
    1.33  		// The XuggleVideoRecorder is better than the AVIVideoRecorder in every way
    1.34  		// except for ease of installation.  The excellent work by Werner Randelshofer
    1.35  		// is used as a fallback option.  Please visit http://www.xuggle.com/ to learn
    1.36  		// how to set up the XuggleVideoRecorder.
    1.37 +
    1.38 +		if (file.getCanonicalPath().endsWith(".avi")){
    1.39 +			videoRecorder = new AVIVideoRecorder(file);}
    1.40 +		else { videoRecorder = new XuggleVideoRecorder(file);}
    1.41 +
    1.42 +		Callable<Object> thunk = new Callable<Object>(){
    1.43 +			public Object call(){
    1.44 +
    1.45 +				ViewPort viewPort = 
    1.46 +						app.getRenderManager()
    1.47 +						.createPostView("aurellem record", app.getCamera());
    1.48 +
    1.49 +				viewPort.setClearFlags(false, false, false);
    1.50 +
    1.51 +				// get GUI node stuff
    1.52 +				for (Spatial s : app.getGuiViewPort().getScenes()){
    1.53 +					viewPort.attachScene(s);
    1.54 +				}
    1.55 +
    1.56 +				app.getStateManager().attach(videoRecorder);
    1.57 +				viewPort.addProcessor(videoRecorder);
    1.58 +				return null;
    1.59 +			}
    1.60 +		};
    1.61 +		app.enqueue(thunk);
    1.62 +	}
    1.63 +
    1.64 +	
    1.65 +	public static void captureAudio(final Application app, final File file) throws IOException{
    1.66 +		AppSettings settings = new AppSettings(true);
    1.67 +		settings.setAudioRenderer("Send");
    1.68 +		app.setSettings(settings);
    1.69 +
    1.70 +		Callable<Object> thunk = new Callable<Object>(){
    1.71 +			public Object call(){
    1.72 +				AudioRenderer ar = app.getAudioRenderer();
    1.73 +				if (ar instanceof MultiListener){
    1.74 +					MultiListener ml = (MultiListener)ar;
    1.75 +					ml.registerSoundProcessor(new WaveFileWriter(file));
    1.76 +				}
    1.77 +				return null;
    1.78 +			}
    1.79 +		};
    1.80  		
    1.81 -		AbstractVideoRecorder videoRecorder;
    1.82 -		
    1.83 -		if (file.getCanonicalPath().endsWith(".avi")){
    1.84 -			 videoRecorder = new AVIVideoRecorder(file);}
    1.85 -		else { videoRecorder = new XuggleVideoRecorder(file);}
    1.86 -		
    1.87 -		app.getStateManager().attach(videoRecorder);
    1.88 -		app.getViewPort().addFinalProcessor(videoRecorder);
    1.89 -	}	
    1.90 +		app.enqueue(thunk);
    1.91 +	}
    1.92 +	
    1.93  }