【发布时间】:2012-11-14 21:14:00
【问题描述】:
我正在开发一个音乐应用程序,其中使用了 Seekbar。我有一种方法可以处理搜索栏的性能,并且效果很好。但如果 seekbar 正在运行,则存在内存泄漏,并且 Log cat 显示为
GC_CONCURRENT freed 1692K, 34% free 10759K, paused 3ms+8ms
当搜索栏正在进行时,这会不断出现
我发现问题是由于TextView的动态更新,即显示当前歌曲的时长。
我该如何解决。请帮我解决这个问题
我的功能是
public void seekbarProgress(){
handler.postDelayed(new Runnable() {
@Override
public void run() {
//current position of the play back
currPos = harmonyService.player.getCurrentPosition();
if(isPaused){
//if paused then stay in the current position
seekBar.setProgress(currPos);
//exiting from method... player paused, no need to update the seekbar
return;
}
//checking if player is in playing mode
if(harmonyService.player.isPlaying()){
//settting the seekbar to current positin
seekBar.setProgress(currPos);
//updating the cuurent playback time
currTime.setText(getActualDuration(""+currPos));
handler.removeCallbacks(this);
//callback the method again, wich will execute aftr 500mS
handler.postDelayed(this, 500);
}
//if not playing...
else{
//reset the seekbar
seekBar.setProgress(0);
//reset current position value
currPos = 0;
//setting the current time as 0
currTime.setText(getActualDuration(""+currPos));
Log.e("seekbarProgress()", "EXITING");
//exiting from the method
return;
}
}
}, 500);
}
【问题讨论】:
-
为什么要随着搜索栏的每个进度更新曲目的长度?您可以在 MediaPlayer 准备好后更新一次。
-
我想在一个 Textview 中更新当前的搜索时间,还有一个 Textview 用于完整的歌曲持续时间,这个 textview 用于当前正在播放的歌曲时间。
-
您多久更改一次搜索栏进度?如果您的文本中不显示毫秒,您可以创建一个线程,根据搜索栏每秒更新 TextView。
-
我的目标是:如果一首歌曲的最大持续时间为 10000 毫秒,我的 textview maxTime 之一,在此方法之外,将显示为 00:10 ,方法是在方法 getActualDuration( timeInMillis)...需要再显示一个TextView currTime,作为歌曲的当前位置。例如:当歌曲开始播放时,它设置为 0,然后在 1 秒后它将更新为 00:01、00:02、00:02 等直到 00:10 ......就像这样
-
您显示的 logcat 条目并不意味着内存泄漏,它只是垃圾收集器在做它的工作。我怀疑这个
""+currPos会导致大量垃圾收集。请阅读 Java“不可变字符串”。
标签: android memory-leaks garbage-collection textview settext