I'm making a Live Wallpaper for Android 2.3.3 and it used the Visualizer class. I've already got a working version of my Visualizer program working as a stand alone but when I place the code into a Live Wallpaper service, my problem begins. The following code is where the error exists:
// Called in my Engine extension's 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'm looking through the live wallpaper list, I'll tap it to view the preview and it works fine. Without setting it as the active wallpaper, I hit the back button and then select it again and it crashes. I can repeat this process and it only crashes every other time and works the other times. If I choose to set it as the active wallpaper, it crashes every time.