summaryrefslogtreecommitdiffstats
path: root/src/plugins/android/src/mediacapture
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2024-01-04 21:21:58 +0200
committerTarja Sundqvist <tarja.sundqvist@qt.io>2024-01-04 21:21:58 +0200
commit374d71e29a142bd177cd5b1b7e29a4628085ddcb (patch)
tree2d0835a2f06d74ff5d750667c4c84bf88f537afb /src/plugins/android/src/mediacapture
parent5197ff9e91cabd90700cf0d36fb5e9e5793d7097 (diff)
parent8d17f204d8aa06f03b5cc17764db28e959073c2a (diff)
Merge remote-tracking branch 'origin/tqtc/lts-5.15.13' into tqtc/lts-5.15-opensourcev5.15.13-lts-lgpl5.15
Diffstat (limited to 'src/plugins/android/src/mediacapture')
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcapturesession.cpp41
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcapturesession.h3
2 files changed, 40 insertions, 4 deletions
diff --git a/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp b/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp
index 9b47d4650..c0484a139 100644
--- a/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp
+++ b/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp
@@ -188,19 +188,30 @@ void QAndroidCaptureSession::setState(QMediaRecorder::State state)
start();
break;
case QMediaRecorder::PausedState:
- // Not supported by Android API
- qWarning("QMediaRecorder::PausedState is not supported on Android");
+ pause();
break;
}
}
void QAndroidCaptureSession::start()
{
- if (m_state == QMediaRecorder::RecordingState || m_status != QMediaRecorder::LoadedStatus)
+ if (m_state == QMediaRecorder::RecordingState
+ || (m_status != QMediaRecorder::LoadedStatus && m_status != QMediaRecorder::PausedStatus))
return;
setStatus(QMediaRecorder::StartingStatus);
+ if (m_state == QMediaRecorder::PausedState) {
+ if (!m_mediaRecorder || !m_mediaRecorder->resume()) {
+ emit error(QMediaRecorder::FormatError, QLatin1String("Unable to resume the media recorder."));
+ if (m_cameraSession)
+ restartViewfinder();
+ } else {
+ updateStartState();
+ }
+ return;
+ }
+
if (m_mediaRecorder) {
m_mediaRecorder->release();
delete m_mediaRecorder;
@@ -289,7 +300,11 @@ void QAndroidCaptureSession::start()
restartViewfinder();
return;
}
+ updateStartState();
+}
+void QAndroidCaptureSession::updateStartState()
+{
m_elapsedTime.start();
m_notifyTimer.start();
updateDuration();
@@ -328,6 +343,7 @@ void QAndroidCaptureSession::stop(bool error)
m_mediaRecorder->stop();
m_notifyTimer.stop();
updateDuration();
+ m_previousElapsedTime = 0;
m_elapsedTime.invalidate();
m_mediaRecorder->release();
delete m_mediaRecorder;
@@ -358,6 +374,23 @@ void QAndroidCaptureSession::stop(bool error)
setStatus(QMediaRecorder::LoadedStatus);
}
+void QAndroidCaptureSession::pause()
+{
+ if (m_state == QMediaRecorder::PausedState || m_mediaRecorder == 0)
+ return;
+
+ setStatus(QMediaRecorder::PausedStatus);
+
+ m_mediaRecorder->pause();
+ m_notifyTimer.stop();
+ updateDuration();
+ m_previousElapsedTime = m_duration;
+ m_elapsedTime.invalidate();
+
+ m_state = QMediaRecorder::PausedState;
+ emit stateChanged(m_state);
+}
+
void QAndroidCaptureSession::setStatus(QMediaRecorder::Status status)
{
if (m_status == status)
@@ -514,7 +547,7 @@ void QAndroidCaptureSession::restartViewfinder()
void QAndroidCaptureSession::updateDuration()
{
if (m_elapsedTime.isValid())
- m_duration = m_elapsedTime.elapsed();
+ m_duration = m_elapsedTime.elapsed() + m_previousElapsedTime;
emit durationChanged(m_duration);
}
diff --git a/src/plugins/android/src/mediacapture/qandroidcapturesession.h b/src/plugins/android/src/mediacapture/qandroidcapturesession.h
index 8cfb9ad2a..cee148a4c 100644
--- a/src/plugins/android/src/mediacapture/qandroidcapturesession.h
+++ b/src/plugins/android/src/mediacapture/qandroidcapturesession.h
@@ -136,7 +136,9 @@ private:
CaptureProfile getProfile(int id);
void start();
+ void updateStartState();
void stop(bool error = false);
+ void pause();
void setStatus(QMediaRecorder::Status status);
@@ -154,6 +156,7 @@ private:
QElapsedTimer m_elapsedTime;
QTimer m_notifyTimer;
qint64 m_duration;
+ qint64 m_previousElapsedTime = 0;
QMediaRecorder::State m_state;
QMediaRecorder::Status m_status;