android.media.audiofx.Visualizer引发异常每个其他时间 [英] android.media.audiofx.Visualizer throwing exception every other time
问题描述
我在做一个动态壁纸为Android 2.3.3,它使用的可视化类。我已经得到了我的可视化程序工作作为一个独立的工作版本,但是当我把code到一个动态壁纸的服务,我的问题开始。下面code是存在错误:
//调用在我的引擎推广的构造
公共无效setupVisualizer()
{
兆字节= NULL;
mVisualizer =新的可视化工具(0); //编辑
mVisualizer.setEnabled(假); //这个修复该问题
// END EDIT mVisualizer.setCaptureSize(
Visualizer.getCaptureSizeRange()[1]); // IllegalStateException异常时抛出 mVisualizer.setDataCaptureListener(){
公共无效onWaveFormDataCapture(可视化可视化工具,
字节[]字节,INT采样速率){
updateVisualizer(字节);
}
公共无效onFftDataCapture(可视化可视化工具,
字节[]字节,INT采样速率){}
},Visualizer.getMaxCaptureRate()/ 2,真,假); mVisualizer.setEnabled(真);
}
这里的怪异的一部分,当我翻翻现场壁纸列表中,我会点击它来查看preVIEW,它工作正常。如果不设置为活动的墙纸,我打的返回按钮,然后再次选择它,它崩溃。我可以重复这个过程,它只是崩溃每个其他时间和作品的其他时间。如果我选择将其设置为活动的墙纸,它崩溃每次。
看<一个href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.4_r1/android/media/audiofx/Visualizer.java\">at源,好像 IllegalStateException异常
被抛出,如果状态不是 STATE_INITIALIZED
。
由于构造函数设置状态 STATE_ENABLED
或 STATE_INITIALIZED
,这意味着国家,当你得到的异常为 STATE_ENABLED
(唯一的选择)。
在的文件 setCaptureSize()
他们提到,虽然国家是你不应该调用此方法 STATE_ENABLED
,所以我觉得你需要
的setEnabled(假)
展示台对象>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.
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()
这篇关于android.media.audiofx.Visualizer引发异常每个其他时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!