I am making a Live Wallpaper for Android 2.3.3 and it used the Visualizer class. I already have a working version of my Visualizer program, which works as a stand-alone, but when I put the code in the Live Wallpaper service, my problem starts. The following code contains an error:
// Called in my Engine extension constructor public void setupVisualizer() { mBytes = null; mVisualizer = new Visualizer(0); // EDIT mVisualizer.setEnabled(false); // This fixes the issue // END EDIT mVisualizer.setCaptureSize( Visualizer.getCaptureSizeRange()[1]); // IllegalStateException Thrown mVisualizer.setDataCaptureListener() { public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) { updateVisualizer(bytes); } public void onFftDataCapture(Visualizer visualizer, bytes[] bytes, int samplingRate) {} }, Visualizer.getMaxCaptureRate() / 2, true, false); mVisualizer.setEnabled(true); }
Here's the weird part, when I look at a list of live wallpapers, I click on it to preview it, and it works great. Without setting it as active wallpaper, I press the back button and then select it again and it crashes. I can repeat this process, and it only crashes every time and works at a different time. If I decide to set it as an active wallpaper, it will be reset every time.
Foggzie
source share