How to count the Framerate with which a SurfaceView refreshes?

前端 未结 2 641
再見小時候
再見小時候 2021-02-11 08:53

I have a third party framework that shows video on a SurfaceView. I would like to measure the framerate of the video to check if the phone is capable of showing the video fast e

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-11 09:07

    try this!

    private long mLastTime = 0;
    private int fps = 0, ifps = 0;
    @Override
    protected void onDraw(Canvas canvas) {
        long now = System.currentTimeMillis();
    
        // perform other operations
    
        System.out.println("FPS:" + fps);
    
        ifps++;
        if(now > (mLastTime + 1000)) {
            mLastTime = now;
            fps = ifps;
        ifps = 0;
        }
    }
    

提交回复
热议问题