0

I am working on a live wallpaper that uses a AudioRecord object to listen to the phone's mic. This works fine until I start using the wallpaper and then also view the preview wallpaper in the wallpaper selection menu. When this happens, I start having problems starting and stopping the AudioRecord object. Currently this is handled by onVisibilityChanged:

    @Override
    public void onVisibilityChanged(boolean visible) {
        if (this.visible == visible)
            return;

        this.visible = visible;
        if (visible) {
            recorder.startRecording();
            handler.post(drawRunner);
        } else {
            recorder.stop();
            handler.removeCallbacks(drawRunner);
        }
    }

Is there some solution to this? I have tried several things, but nothing has worked out. This solution does (rarely) work, and as far as I can tell this is because the two instances of the wallpaper engine update their visibility in an unpredictable order. Sometimes the main wallpaper sets itself to not be visible before the preview sets itself to be visible, and everything is fine. Sometimes this order is reversed and everything breaks.

1 Answers1

0

So, I found an answer and it was stupidly simple. I swear I tried this already and it didn't work, but everything is working fine now. All I had to do was move the AudioRecord object outside of the engine class and into the service class. I then create the AudioRecord object in onCreateEngine only if it isn't already instantiated. That way, all engine instances use the same AudioRecord object.