我为我的网络应用程序提供了这个代码,我需要一些改进,它以某种方式工作,但结果很慢:
此代码背后的理念是:
更新(简化代码):
private String data = "";
// This function renders the waveform in the page, has been tested to
// render properly and smoothly by passing random double value at 50ms interval
public void updateWave(String waveValue){
wave.renderWaveOnFly(Double.parseDouble(waveValue));
}
public final native void waveIt()/*-{
var instance = this;
$wnd._waver = setInterval(function(){
// Get the current buffer from the flash interface
// Note it fetches everything in the buffer
var newData = $wnd.Recorder.audioData().toString();
var strData = newData.toString();
var arr = strData.split(',');
var arrEl = arr.pop();
instance.@com.mycode.wavegwt.showcase.client.Showcase::updateWave(Ljava/lang/String;)(arrEl.toString());
//console.log(arrEl);
}
,50);
}-*/;
// This function renders the waveform from math function
// and the waveform is smooth and the UI is still responsive
public final native void waveItByRandomValue()/*-{
var instance = this;
$wnd._waver = setInterval(function(){
var arrEl = Math.cos(i++/25) - 0.2 + Math.random() * 0.3;
instance.@com.mycode.wavegwt.showcase.client.Showcase::updateWave(Ljava/lang/String;)(arrEl.toString());
}
,50);
}-*/;
public native void renderWaveOnFly(Double _data)/*-{
var data = $wnd.data;
data.push(_data);
$wnd._waveform.update({
data: data
});
}-*/;
waveIt()
是一个从闪存接口读取缓冲区的函数(从麦克风获取数据)。对于演示,我将麦克风录音机设置为在触发时记录10秒,然后在录音开始时waveIt()
,在10秒后拨打clearInterval($wnd._waver)
问题:
waveIt()
函数非常慢,即在运行此UI时没有响应,并且渲染速度很慢waveItByRandomValue()
相比,运行此功能时UI仍然响应我没有关于如何使这项工作正确的战略。
要查看我的项目,请参阅:http://bitly.com/XGboA1
我也在Google网上论坛中解释了这个问题:http://bitly.com/SqSZVl