josuigoa / CameraMic

Camera & Microphone OpenFL native extension
32 stars 6 forks source link

JNI Exception on Android #6

Closed ashes999 closed 9 years ago

ashes999 commented 9 years ago

Hi,

I have an app where I've embedded recording inside one of many scenes, and I allow the user to change scenes by swiping left and right.

I noticed this workflow generates a crash:

This is presumably because the recording device is already occupied. Since the class is static, it's not automatically destroyed when I change states.

Here's what the log files say:

could not get audio input for record source 1 audio source is not initialized start failed: -2147483648 Java.lang.RuntimeException: start failed at android.media.MediaReorder.native_start(Native Method) ... JNI Exception

I assume the work-around for this is to store and detect if the user is recording, and if so, force a stop recording when the scene changes.

josuigoa commented 9 years ago

I think that's the trick, yes. Store if it is recording and check it when you change the scene. Or do you need to continue recording while you set the scene?

ashes999 commented 9 years ago

No, this workflow is fine for me. I stop the recording behind the scenes if the scene disposes.

Are the recording files automatically cleaned up at some point, or do they stay on the device forever? :)

josuigoa commented 9 years ago

if you use this line sys.FileSystem.deleteFile(_audioPath); with your audio paths, it won't be there forever ;)

ashes999 commented 9 years ago

Uhoh. This really should be mentioned in the readme somewhere.

Is that right?

josuigoa commented 9 years ago

yes, that is right. This is how my callback function looks like in another app:

function onRecordAudioClick(me:MouseEvent):Void
    {
        if (_audioPath != null && sys.FileSystem.exists(_audioPath))
            sys.FileSystem.deleteFile(_audioPath);
               //...
     }

is this enough or do you propose some way to do it at the extension?

ashes999 commented 9 years ago

That's enough to get it working. It would be better if I could specify this in a parameter somewhere, but this will do very nicely.

josuigoa commented 9 years ago

Ok! It's a good idea to specify in a parameter, I'll do that, thank you!