MediaDevices QML Type

MediaDevices 提供有关可用多媒体输入和输出设备的信息。更多

Import Statement: import QtMultimedia
In C++: QMediaDevices

属性

详细说明

MediaDevices 类型提供有关可用多媒体设备和系统默认设置的信息。它监控以下三组设备:

  • 音频输入设备(麦克风)
  • 音频输出设备(扬声器、耳机)
  • 视频输入设备(摄像头)

MediaDevices 为每个设备组提供单独的列表。如果检测到有新设备连接到系统或已连接的设备从系统断开连接,它就会更新相应的设备列表,并发出信号通知这一变化。

MediaDevices 会监控每个设备组的系统默认设置。如果通过系统设置进行了任何更改,它都会发出通知。例如,如果用户在系统设置中选择了新的默认音频输出,MediaDevices 将相应更新默认音频输出并发出信号。如果系统没有提供摄像机或音频输入的默认设置,MediaDevices 将从列表中选择第一个设备作为默认设备。

虽然使用默认输入和输出设备通常足以满足播放或录制多媒体的需要,但也经常需要明确选择要使用的设备。

例如,下面的代码段将确保媒体播放器始终使用系统默认的音频输出设备进行播放:

MediaDevices {
    id: devices
}
MediaPlayer {
    ...
    audioOutput: AudioOutput {
        device: devices.defaultAudioOutput
    }
}

另请参阅 Camera,AudioInput, 和VideoOutput

属性文档

audioInputs : list<audioDevice> [read-only]

包含系统中可用音频输入设备的列表。

这些设备通常是麦克风。设备可以是内置的,也可以通过 USB 或蓝牙等方式连接。


audioOutputs : list<audioDevice> [read-only]

包含系统上可用音频输出设备的列表。

这些设备通常是扬声器或耳机。这些设备可以是内置的,也可以通过 USB 或蓝牙连接。


defaultAudioInput : audioDevice [read-only]

返回默认音频输入设备。

默认设备可在应用程序运行期间更改。该属性的值将根据这些变化自动调整。


defaultAudioOutput : audioDevice [read-only]

返回默认音频输出设备。

默认设备可在应用程序运行期间更改。该属性的值将根据这些变化自动调整。


defaultVideoInput : cameraDevice [read-only]

返回系统中的默认摄像机。

注意: 在使用前应使用 isNull() 检查返回的对象,以防没有可用的摄像机。

在应用程序运行期间,默认设备可能会发生变化。该属性的值将根据这些变化自动调整。


videoInputs : list<cameraDevice> [read-only]

包含系统中的摄像机列表。


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.