문제

I'm trying to hook up a basic audio player. The audio side is done, but I'm using a SeekBar as a track scrubber and I'm having trouble with performance.

The SeekBar is from an XML layout, and I'm using fairly basic code to update it:

updateTask = new Runnable() {

    public void run() {

        int elapsed = 0;
        if (player != null) {
            elapsed = player.getElapsedTime(); // Seconds
        }
        trackSeekbar.setProgress(elapsed);
        updateHandler.postDelayed(this, 1000);
    }

};

updateHandler.postDelayed(updateTask, 1000);

This code is taking between 20%–50% CPU on a Nexus 10! It makes other parts of my app are very choppy so it has to be faster.

I have already taken out some things in the layout to try and reduce layout redraws (I was displaying the elapsed time in a text box but gave up because it was just too slow), but I do need a basic scrubber. When I take out the call to setProgress() CPU drops to 1%. Is there a better way of doing this?

도움이 되었습니까?

해결책

The cause of the poor performance was a high resolution transparent PNG in the background. When I removed it, all the various performance issues disappeared.

On the Nexus 10, the image was 2560x1440 which is its native resolution. Seemingly Android is not able to cope with full resolution background images.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top