diff options
author | Artem Dyomin <artem.dyomin@qt.io> | 2023-03-14 11:40:27 +0100 |
---|---|---|
committer | Artem Dyomin <artem.dyomin@qt.io> | 2023-03-15 08:19:55 +0000 |
commit | d15da910c021d37949a9551f0df0d96617338930 (patch) | |
tree | 4054d46fee96b5ccc8d78734a0eff4e51c542f6a /examples | |
parent | 92d1e5eeb368bef99cdfda7ab3c6684eab83a306 (diff) | |
download | qtmultimedia-d15da910c021d37949a9551f0df0d96617338930.tar.gz |
Add screen capturing video source to the media recorder example
The proposition is to add available screens to the same list as
cameras because both can be considered as a videosource for
media capture session.
Pick-to: 6.5
Change-Id: I027194573ae131ec154c566f88370a1ac8adc7df
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Diffstat (limited to 'examples')
6 files changed, 77 insertions, 42 deletions
diff --git a/examples/multimedia/video/recorder/CMakeLists.txt b/examples/multimedia/video/recorder/CMakeLists.txt index ec84533e4..ab7b449d1 100644 --- a/examples/multimedia/video/recorder/CMakeLists.txt +++ b/examples/multimedia/video/recorder/CMakeLists.txt @@ -25,7 +25,7 @@ set(resource_files "qmldir" "MediaList.qml" "AudioInputSelect.qml" - "CameraSelect.qml" + "VideoSourceSelect.qml" "RecordButton.qml" "Controls.qml" "StyleParameter.qml" diff --git a/examples/multimedia/video/recorder/CameraSelect.qml b/examples/multimedia/video/recorder/CameraSelect.qml deleted file mode 100644 index 9abbfabf0..000000000 --- a/examples/multimedia/video/recorder/CameraSelect.qml +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick -import QtQuick.Controls -import QtMultimedia - -Row { - id: root - height: Style.height - property Camera selected: available ? camera : null - property bool available: (typeof comboBox.currentValue !== 'undefined') && cameraSwitch.checked - - Camera { - id: camera - active: available && selected != null - } - - MediaDevices { id: mediaDevices } - - Switch { - id: cameraSwitch - anchors.verticalCenter: parent.verticalCenter - checked: true - } - - ComboBox { - id: comboBox - width: Style.widthLong - height: Style.height - background: StyleRectangle { anchors.fill: parent } - model: mediaDevices.videoInputs - displayText: typeof currentValue === 'undefined' ? "Unavailable" : currentValue.description - font.pointSize: Style.fontSize - textRole: "description" - onCurrentValueChanged: if (typeof comboBox.currentValue !== 'undefined') camera.cameraDevice = currentValue - } -} diff --git a/examples/multimedia/video/recorder/Controls.qml b/examples/multimedia/video/recorder/Controls.qml index 7fbd4c20b..3c04cef83 100644 --- a/examples/multimedia/video/recorder/Controls.qml +++ b/examples/multimedia/video/recorder/Controls.qml @@ -14,7 +14,8 @@ Row { property bool capturesVisible: false property alias audioInput: audioInputSelect.selected - property alias camera: cameraSelect.selected + property alias camera: videoSourceSelect.selectedCamera + property alias screenCapture: videoSourceSelect.selectedScreenCapture spacing: Style.interSpacing * Style.ratio @@ -22,7 +23,7 @@ Row { id: inputControls spacing: Style.intraSpacing - CameraSelect { id: cameraSelect } + VideoSourceSelect { id: videoSourceSelect } AudioInputSelect { id: audioInputSelect } } diff --git a/examples/multimedia/video/recorder/VideoSourceSelect.qml b/examples/multimedia/video/recorder/VideoSourceSelect.qml new file mode 100644 index 000000000..578841d8a --- /dev/null +++ b/examples/multimedia/video/recorder/VideoSourceSelect.qml @@ -0,0 +1,71 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Controls +import QtMultimedia + +Row { + id: root + height: Style.height + property Camera selectedCamera: cameraAvailable ? camera : null + property ScreenCapture selectedScreenCapture: screenAvailable ? screenCapture : null + property bool cameraAvailable: (comboBox.currentValue === 'camera') && cameraSwitch.checked + property bool screenAvailable: (comboBox.currentValue === 'screen') && cameraSwitch.checked + Component.onCompleted: { + videoSourceModel.populate() + comboBox.currentIndex = 0 + } + + Camera { + id: camera + active: cameraAvailable + } + + ScreenCapture { + id: screenCapture + active: screenAvailable + } + + MediaDevices { id: mediaDevices } + + Switch { + id: cameraSwitch + anchors.verticalCenter: parent.verticalCenter + checked: true + } + + ListModel { + id: videoSourceModel + property var cameras: mediaDevices.videoInputs + property var screens: Application.screens + + function populate() { + videoSourceModel.clear() + + for (var camera of cameras) + videoSourceModel.append({ text: camera.description, value: 'camera' }) + + for (var screen of screens) + videoSourceModel.append({ text: screen.name, value: 'screen' }) + } + } + + ComboBox { + id: comboBox + width: Style.widthLong + height: Style.height + background: StyleRectangle { anchors.fill: parent } + model: videoSourceModel + displayText: typeof currentValue === 'undefined' ? "Unavailable" : currentText + font.pointSize: Style.fontSize + textRole: "text" + valueRole: "value" + onCurrentValueChanged: { + if (currentValue === 'screen') + screenCapture.screen = videoSourceModel.screens[currentIndex - videoSourceModel.cameras.length] + else if (currentValue === 'camera') + camera.cameraDevice = videoSourceModel.cameras[currentIndex] + } + } +} diff --git a/examples/multimedia/video/recorder/doc/src/recorder.qdoc b/examples/multimedia/video/recorder/doc/src/recorder.qdoc index 9eb743b1e..d609b0c9a 100644 --- a/examples/multimedia/video/recorder/doc/src/recorder.qdoc +++ b/examples/multimedia/video/recorder/doc/src/recorder.qdoc @@ -13,7 +13,7 @@ \image qmlrecorder.jpg \e{QML Recorder} demonstrates a simple application that can record - audio and or video files using the camera and microphone. + audio and or video files using a microphone, a camera, or screen capturing. \include examples-run.qdocinc diff --git a/examples/multimedia/video/recorder/main.qml b/examples/multimedia/video/recorder/main.qml index c607237f7..b2d3b1ec2 100644 --- a/examples/multimedia/video/recorder/main.qml +++ b/examples/multimedia/video/recorder/main.qml @@ -35,6 +35,7 @@ Window { recorder: recorder audioInput: controls.audioInput camera: controls.camera + screenCapture: controls.screenCapture videoOutput: videoOutput } |