Android: restart camera viewfinder after a recorder error.
authorYoann Lopes <yoann.lopes@digia.com>
Thu, 13 Mar 2014 15:28:57 +0000 (16:28 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 17 Mar 2014 12:48:38 +0000 (13:48 +0100)
Change-Id: I33f083fda5c10cfb997a21100c0ec3d4a314aee0
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
src/plugins/android/src/mediacapture/qandroidcapturesession.cpp
src/plugins/android/src/mediacapture/qandroidcapturesession.h

index 3e5c261..008ebc7 100644 (file)
@@ -225,13 +225,13 @@ bool QAndroidCaptureSession::start()
 
     if (!m_mediaRecorder->prepare()) {
         emit error(QMediaRecorder::FormatError, QLatin1String("Unable to prepare the media recorder."));
-        setStatus(QMediaRecorder::UnloadedStatus);
+        restartViewfinder();
         return false;
     }
 
     if (!m_mediaRecorder->start()) {
         emit error(QMediaRecorder::FormatError, QLatin1String("Unable to start the media recorder."));
-        setStatus(QMediaRecorder::UnloadedStatus);
+        restartViewfinder();
         return false;
     }
 
@@ -258,17 +258,15 @@ void QAndroidCaptureSession::stop(bool error)
     updateDuration();
     m_elapsedTime.invalidate();
 
-    if (m_cameraSession) {
-        m_cameraSession->camera()->reconnect();
-        // Viewport needs to be restarted
-        m_cameraSession->camera()->startPreview();
-        m_cameraSession->setReadyForCapture(true);
-    }
-
     m_mediaRecorder->release();
     delete m_mediaRecorder;
     m_mediaRecorder = 0;
 
+    if (m_cameraSession) {
+        // Viewport needs to be restarted after recording
+        restartViewfinder();
+    }
+
     if (!error) {
         // if the media is saved into the standard media location, register it
         // with the Android media scanner so it appears immediately in apps
@@ -426,6 +424,13 @@ void QAndroidCaptureSession::updateViewfinder()
     m_resolutionDirty = false;
 }
 
+void QAndroidCaptureSession::restartViewfinder()
+{
+    m_cameraSession->camera()->reconnect();
+    m_cameraSession->camera()->startPreview();
+    m_cameraSession->setReadyForCapture(true);
+}
+
 void QAndroidCaptureSession::updateDuration()
 {
     if (m_elapsedTime.isValid())
index fc8300d..32ca9d1 100644 (file)
@@ -144,6 +144,7 @@ private:
     void setStatus(QMediaRecorder::Status status);
 
     void updateViewfinder();
+    void restartViewfinder();
 
     JMediaRecorder *m_mediaRecorder;
     QAndroidCameraSession *m_cameraSession;