I tried various things to overcome the limitation of setPreviewDisplay
():

- preserved the surface (sf), so mSurfaceHolder.getSurface() was not
called again. Worked fine while the surface was visible, but once it
was destroyed, sf.isValid() returned false, and prepare() failed
again

- tried to use the other 3 types of SURFACE_TYPE_*. Preview was not
working, but video was being captured, until it needed to be
initialized again, when prepare() failed

- with these other 3 types of surface, I tried
mSurfaceHolder.lockCanvas(), sf.lockCanvas(dirtyrect) and sf.freeze()
in an attempt to keep the surface being destroyed

Nothing has worked as expected :( Is there a way to keep a valid
surface when the view is pushed to the background? Or, make
setPreviewDisplay() accept a dummy surface?

Thanks,
Robert


On Aug 5, 1:10 pm, Robert <ferob...@gmail.com> wrote:
> Hello all,
>
> I am building a camera app, where photos and videos are continuously
> being captured and saved to the SD card. The videos are short (few
> minutes), and their length are preset with setMaxDuration(). When
> MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED is reached, the
> video is saved, and a new sequence is initialized with something like:
>
>         mMediaRecorder = new MediaRecorder();
>         mMediaRecorder.setVideoSource
> (MediaRecorder.VideoSource.CAMERA);
>         mMediaRecorder.setOutputFormat
> (MediaRecorder.OutputFormat.THREE_GPP);
>         mMediaRecorder.setVideoFrameRate(20);
>         mMediaRecorder.setVideoSize(176, 144);
>         mMediaRecorder.setVideoEncoder
> (MediaRecorder.VideoEncoder.H263);
>         mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
>         mMediaRecorder.setMaxDuration(1000 * Integer.valueOf
> (videoLength));
>         mMediaRecorder.setOnInfoListener(videoInfoListener);
>         mMediaRecorder.setOutputFile("/sdcard/test.3gp");
>         mMediaRecorder.prepare();
>         mMediaRecorder.start();
>
> I also have a SurfaceHolder mSurfaceHolder, set up like:
>
>         mPreview = (SurfaceView) findViewById(R.id.preview);
>         mSurfaceHolder = mPreview.getHolder();
>         mSurfaceHolder.addCallback(this);
>         mSurfaceHolder.setType
> (SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
>
>         public void surfaceCreated(SurfaceHolder holder) {
>             mSurfaceHolder = holder;
>         }
>
>         public void surfaceChanged(SurfaceHolder holder, int format, int w,
> int h) {
>         }
>
>         public void surfaceDestroyed(SurfaceHolder holder) {
>             mSurfaceHolder = null;
>         }
>
> The whole process works fine, while the main activity is in the
> foreground. But, when I go to another activity (e.g. settings), the
> video recording works in the background only until max duration is
> reached. The file is saved, but a new sequence can not be started
> because prepare() fails. setPreviewDisplay() needs to be there, but it
> doesn't like not having a proper surface to attach to.
>
> I tried to use a dummy Surface, a dummy SurfaceHolder, or reuse the
> Camera with mMediaRecorder.setCamera(), but nothing works. Is there a
> way to initialize MediaRecorder in the background?
>
> Thanks and regards,
> Robert
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to