android.media.audiofx.Visualizer 每隔一段时间就会抛出异常

发布于 2025-01-03 20:28:37 字数 1041 浏览 1 评论 0原文

我正在为 Android 2.3.3 制作动态壁纸,它使用了 Visualizer 类。我已经有了一个可以独立运行的 Visualizer 程序的工作版本,但是当我将代码放入动态壁纸服务中时,我的问题就开始了。以下代码是错误存在的地方:

// 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);
}

这是奇怪的部分,当我查看动态壁纸列表时,我会点击它来查看预览,它工作正常。在没有将其设置为活动壁纸的情况下,我点击后退按钮,然后再次选择它,然后它崩溃了。我可以重复这个过程,它只会每隔一次崩溃一次,而其他时候则有效。如果我选择将其设置为活动壁纸,它每次都会崩溃。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

絕版丫頭 2025-01-10 20:28:37

寻找 在源代码中,如果状态不是STATE_INITIALIZED,则似乎会抛出IllegalStateException

由于构造函数将状态设置为 STATE_ENABLEDSTATE_INITIALIZED,这意味着您收到异常时的状态是 STATE_ENABLED (唯一的选项)。

在 setCaptureSize() 的文档中,他们提到当状态为 STATE_ENABLED 时不应调用此方法,因此我认为您需要调用 setEnabled(false) 在调用 setCaptureSize() 之前在 Visualizer 对象上

Looking at the source, it seems like IllegalStateException is thrown if the state is not STATE_INITIALIZED.

Since the constructor sets the state to STATE_ENABLED or STATE_INITIALIZED, it means that the state when you get the exception is STATE_ENABLED (the only option).

In the documentation of setCaptureSize() they mention that you should not call this method while the state is STATE_ENABLED, so I think you need to call setEnabled(false) on the Visualizer object before calling setCaptureSize()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文