AsyncTask的开放式摄像机 [英] AsyncTask Open Camera

查看:139
本文介绍了AsyncTask的开放式摄像机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用全屏幕活动 SurfaceHolder ,打开相机preVIEW(根据 zxing code)。

I've an activity that uses full screen SurfaceHolder, opening camera for preview (based on zxing code).

启动这项活动结果慢(1.x的第二个),我想是因为相机管理的繁重工作。我使用 onResume 方法;它是移动code里面的一个好主意的的AsyncTask

Starting this activity results slow (1.x second), I think because of the heavy lifting of the camera manager. I'm using onResume method; is it a good idea to move the code inside an AsyncTask?

我想立即呈现布局,然后等待相机(我认为这是一个更好的用户体验)。我该如何处理呢?

I'd like to immediately render the layout and then wait for the camera (i think it's a better user experience). How can i handle this?

活动

private class CameraTask extends AsyncTask<Void, Void, Void> {
    SurfaceHolder.Callback callback;

    public CameraTask(SurfaceHolder.Callback callback) {
        this.callback = callback;
    }
    protected void doInBackground() {
        cameraManager = new CameraManager(getApplication());
        viewfinderView = (ViewFinderView) findViewById(R.id.viewfinder_view);
        viewfinderView.setCameraManager(cameraManager);
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();

        if (hasSurface) {
            initCamera(surfaceHolder);
        } else {
            surfaceHolder.addCallback(callback);
        }
    }
}

这code没有错误,但布局渲染还是等到相机开启。
我打电话 onResume 执行的的AsyncTask 方法,它是正确的位置?

This code has no errors, but layout rendering still wait for camera opening. I'm calling execute method of AsyncTask in onResume, is it the correct location?

推荐答案

解决方案在这里找到:<一href=\"http://stackoverflow.com/questions/7119164/show-my-layout-while-surfaceview-is-loading-camera-$p$pview\">Show而SurfaceView加载摄像头preVIEW 我的布局。基本上,编程而不是添加SurfaceView你的XML布局中。

Solution found here: Show my Layout while SurfaceView is loading Camera Preview. Basically, add SurfaceView programatically and not inside your xml layout.

这篇关于AsyncTask的开放式摄像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆