Howto stop recording?

I’ve read the audio/video capturing tutorial, https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:capture_audio_video_to_a_file, and now I got this code:



[java]

public static void record( int fps, String videoFileName, File videoFileDirectory, String soundFileName, File soundFileDirectory )

{

try

{

File video = File.createTempFile( videoFileName, “.avi”, videoFileDirectory );

File audio = File.createTempFile( soundFileName, “.wav”, soundFileDirectory );



app.setTimer( new IsoTimer(fps) );



Capture.captureVideo( app, video );

Capture.captureAudio( app, audio );

}

catch( Exception e )

{

//TODO: show error to user

}

}

[/java]



But now I want to stop recording, how do I do this without closing the app?

Through this API I don’t know. But if you used



[java]stateManager.attach(new VideoRecorderAppState());[/java]



Just get the instance of that AppState and remove from the StateManager.



Looking at the source of that API, to stop recording, just ask the StateManager to get a AbstractVideoRecorder.class instance, and remove from the StateManager. But I have to agree that it could have a stop mechanism.

Does the VideoRecorderAppState also records sound?

@patrickvane1993 said:
Does the VideoRecorderAppState also records sound?

No, thats more complicated than it.... sounds ^^

So, how can I record sounds? (with the option to stop recording)

Well, I don’t know. You could try taking a look at the source code provided by that tutorial. Just unzip that archive, delete all .class files and put the java in some project you have. Now, try to take a look and see if you can find a way to stop recording. Try to check how the audio recording starts, and see if you can halt it.

The code for recording is:



Video:

[java]

public static void captureVideo(final Application app, final File file) throws IOException{

final AbstractVideoRecorder videoRecorder;



if (file.getCanonicalPath().endsWith(".avi")){

videoRecorder = new AVIVideoRecorder(file);}

else if (file.isDirectory()){

videoRecorder = new FileVideoRecorder(file);}

else { videoRecorder = new XuggleVideoRecorder(file);}



Callable<Object> thunk = new Callable<Object>(){

public Object call(){



ViewPort viewPort =

app.getRenderManager()

.createPostView("aurellem video record", app.getCamera());



viewPort.setClearFlags(false, false, false);



// get GUI node stuff

for (Spatial s : app.getGuiViewPort().getScenes()){

viewPort.attachScene(s);

}



app.getStateManager().attach(videoRecorder);

viewPort.addProcessor(videoRecorder);

return null;

}

};

app.enqueue(thunk);

}

[/java]



Sound:

[java]

public static void captureAudio(final Application app, final File file) throws IOException{

AppSettings settings = null;

if (app.getContext() != null){settings = app.getContext().getSettings();}

if (settings == null){settings = new AppSettings(true);}

settings.setAudioRenderer("Send");

app.setSettings(settings);



JmeSystem.setSystemDelegate(new AurellemSystemDelegate());



final WaveFileWriter writer = new WaveFileWriter(file);



Callable<Object> thunk = new Callable<Object>(){

public Object call(){

AudioRenderer ar = app.getAudioRenderer();

if (ar instanceof MultiListener){

MultiListener ml = (MultiListener)ar;

ml.registerSoundProcessor(writer);

}

return null;

}

};

app.enqueue(thunk);

}

[/java]



It looks like we can stop the recording by undoing this:

[java]app.enqueue(thunk);[/java]



Can anyone verify if this is correct?

If that is not the case, video recording can be stopped by reversing this:

[java]

app.getStateManager().attach(videoRecorder);

viewPort.addProcessor(videoRecorder);

[/java]



And sound recording could be stopped by reversing this:

[java]

ml.registerSoundProcessor(writer);

[/java]

1 Like

Can anyone change the recorder libs to add pause/stop functionality, or do I need to do this myself?

@patrickvane1993 said:
Can anyone change the recorder libs to add pause/stop functionality, or do I need to do this myself?


You could change this behavior and post this back. It's really a community, so every member can help everyone ^^ Watch out to make sure that's the only thing that needs to be done. I know that for Video, that is correct, but for sound, I think you may need to remove something else from somewhere.
1 Like

Ok thanks for the replies. Currently I’m still learning jME, so this function has a low priority for me.

Maybe later, in a couple months or so, I’ll add this function (if nobody else has done it before me). When I do, I’ll make sure to post it on the forums.

1 Like

Detach it to stop it. It doesn’t just record but also bend the time and in case of the audio recorder mess up the whole system. The detaching is much more consistent to disable all that. All this is in the wiki too.

I think you’re confusing the simple way with the advanced way.

The simple way, with the VideoRecorderAppState, stops when you detach it yes, but it doesn’t record sound.

The advanced way does record sound, but there is no way to stop it from recording now. As far as I know, you can’t detach anything for the advanced way, because you’re not attaching anything either.



With the simple and advanced way I mean the ways in here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:capture_audio_video_to_a_file, which are:



Simple:

[java]stateManager.attach(new VideoRecorderAppState()); //start recording[/java]



Advanced:

[java]

app.setTimer( new IsoTimer(60) );



File video = File.createTempFile( “JME-water-video”, “.avi” );

File audio = File.createTempFile( “JME-water-audio”, “.wav” );



Capture.captureVideo( app, video );

Capture.captureAudio( app, audio );

[/java]

The simple one bends time as well, I wrote this stuff man…

Yes, but I don’t mean about that, it’s about that I also want to record sound, so I won’t be using the simple one.

The advanced one can’t be detached for as far as I know.

Yes, the “advanced” recorder cannot be removed, you’re always free to add this functionality. The person who wrote it simply gave it to us and went off so any maintenance has be done by contributors.