Android: restart camera viewfinder after a recorder error.

Change-Id: I33f083fda5c10cfb997a21100c0ec3d4a314aee0
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
Yoann Lopes
2014-03-13 16:28:57 +01:00
committed by The Qt Project
parent cd0533166f
commit 8463aae9c0
2 changed files with 15 additions and 9 deletions

View File

@@ -225,13 +225,13 @@ bool QAndroidCaptureSession::start()
if (!m_mediaRecorder->prepare()) { if (!m_mediaRecorder->prepare()) {
emit error(QMediaRecorder::FormatError, QLatin1String("Unable to prepare the media recorder.")); emit error(QMediaRecorder::FormatError, QLatin1String("Unable to prepare the media recorder."));
setStatus(QMediaRecorder::UnloadedStatus); restartViewfinder();
return false; return false;
} }
if (!m_mediaRecorder->start()) { if (!m_mediaRecorder->start()) {
emit error(QMediaRecorder::FormatError, QLatin1String("Unable to start the media recorder.")); emit error(QMediaRecorder::FormatError, QLatin1String("Unable to start the media recorder."));
setStatus(QMediaRecorder::UnloadedStatus); restartViewfinder();
return false; return false;
} }
@@ -258,17 +258,15 @@ void QAndroidCaptureSession::stop(bool error)
updateDuration(); updateDuration();
m_elapsedTime.invalidate(); 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(); m_mediaRecorder->release();
delete m_mediaRecorder; delete m_mediaRecorder;
m_mediaRecorder = 0; m_mediaRecorder = 0;
if (m_cameraSession) {
// Viewport needs to be restarted after recording
restartViewfinder();
}
if (!error) { if (!error) {
// if the media is saved into the standard media location, register it // if the media is saved into the standard media location, register it
// with the Android media scanner so it appears immediately in apps // with the Android media scanner so it appears immediately in apps
@@ -426,6 +424,13 @@ void QAndroidCaptureSession::updateViewfinder()
m_resolutionDirty = false; m_resolutionDirty = false;
} }
void QAndroidCaptureSession::restartViewfinder()
{
m_cameraSession->camera()->reconnect();
m_cameraSession->camera()->startPreview();
m_cameraSession->setReadyForCapture(true);
}
void QAndroidCaptureSession::updateDuration() void QAndroidCaptureSession::updateDuration()
{ {
if (m_elapsedTime.isValid()) if (m_elapsedTime.isValid())

View File

@@ -144,6 +144,7 @@ private:
void setStatus(QMediaRecorder::Status status); void setStatus(QMediaRecorder::Status status);
void updateViewfinder(); void updateViewfinder();
void restartViewfinder();
JMediaRecorder *m_mediaRecorder; JMediaRecorder *m_mediaRecorder;
QAndroidCameraSession *m_cameraSession; QAndroidCameraSession *m_cameraSession;