简体   繁体   English

Android Camera Application,预览崩溃

[英]Android Camera Application, preview crash

So I started with this little write-up. 因此,我从这篇小文章开始。 I wanted to try to make an application that will take pictures while running in the background. 我想尝试制作一个可以在后台运行时拍照的应用程序。 To start though I wanted an application that once opened would simply take a picture every X seconds. 首先,我想要一个一旦打开的应用程序,只需每X秒拍摄一张照片。 After recreating the classes and methods show in the walk through below I ran into a few problems. 重新创建下面的演练中显示的类和方法后,我遇到了一些问题。

http://itp.nyu.edu/~sve204/mobilemedia_spring10/androidCamera101.pdf http://itp.nyu.edu/~sve204/mobilemedia_spring10/androidCamera101.pdf

For starters its seems that the onCreate function sets up all the objects for the application, but if you try to take a picture through any other method than onClick (IE directly calling it) the application actually hasn't setup the canvas or the preview yet. 对于初学者来说,似乎onCreate函数为应用程序设置了所有对象,但是如果您尝试通过除onClick(IE直接调用它)以外的任何其他方法拍照,则应用程序实际上尚未设置画布或预览。

My first question: Is there any conditional method that you can setup that will wait till all the "onCreate" objects are created and their associated methods are called and finished? 我的第一个问题:您可以设置任何条件方法来等待所有“ onCreate”对象创建以及它们的关联方法被调用并完成吗? How do I wait for the application to finish putting together my surface and starting the cameras preview before automatically starting to take pictures? 在自动开始拍照之前,如何等待应用程序完成对表面的整理并开始相机预览?

My second question: I am required to have a preview available to take pictures. 我的第二个问题:我需要具有预览功能才能拍照。 Is there anyway to push this application to the back (IE running in the background) while still taking pictures? 无论如何,仍然可以在拍照的同时将该应用程序推回后台(IE在后台运行)? Is drawing to a canvas a requirement? 是否需要在画布上绘画? (From what I can tell AFAIK, you are required to have a surfaceholder to start preview, when you put up another screen or application that pauses the current application and closes the surface/canvas you were presenting that preview on). (据我所知AFAIK,当您放置另一个屏幕或应用程序以暂停当前应用程序并关闭要在其上显示预览的表面/画布时,需要具有一个Surfaceholder来开始预览)。 If my understanding is correct on all of this the best I will be able to do is make a 1x1 pixel canvas that will still take up the screen due to the application being in the foreground. 如果我对这一切的理解是正确的,那么我将能够做的最好的事情就是制作一个1x1像素的画布,由于应用程序位于前台,因此该画布仍会占据屏幕。

My Third question: is there any way around this? 我的第三个问题:这有什么办法吗? Can you still utilize the camera in some fashion without requiring the preview be drawn? 您是否仍可以以某种方式使用相机而无需绘制预览?

  1. You have to implement SurfaceHolder.Callback and wait for it's surfaceCreated() to be called. 您必须实现SurfaceHolder.Callback并等待它的surfaceCreated()被调用。

    After that you can do all MediaRecorder preparation (setPreviewDisplay,setAudio, setVideo, prepare()). 之后,您可以准备所有MediaRecorder (setPreviewDisplay,setAudio,setVideo,prepare())。

  2. You can overlay SurfaceView with another view and thus hide it. 您可以用另一个视图覆盖SurfaceView,从而将其隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM