Qt 提供多媒体支持通过 Qt Multimedia 模块。Qt Multimedia 模块提供丰富特征集,使您能够轻松利用平台的多媒体能力,譬如:媒体回放和使用摄像头设备。
这里是采用 Qt Multimedia API 可以做的一些事情:
Qt Multimedia API 分为 3 个主要组件。概述页面有为每组件提供更多特定信息。您也可以查看一些 配方 .
一些快速配方,见下表:
用例 | 范例 | QML 类型 | C++ 类 |
---|---|---|---|
播放音效 | SoundEffect | QSoundEffect | |
Playing 3D sound | audiopanning | SpatialSound , AudioEngine | QSpatialSound , QAudioEngine |
播放编码音频 (MP3 AAC 等) | player | MediaPlayer | QMediaPlayer |
以低延迟播放原生音频数据 | audiooutput | QAudioSink | |
访问原生音频输入数据 | spectrum , audiosource | QAudioSource | |
录制编码音频数据 | audiorecorder | CaptureSession , AudioInput , MediaRecorder | QMediaCaptureSession , QAudioInput , QMediaRecorder |
探索音频和视频设备 | audiodevices | MediaDevices , audioDevice , cameraDevice | QMediaDevices , QAudioDevice , QCameraDevice |
视频回放 | player , mediaplayer | MediaPlayer , VideoOutput , 视频 | QMediaPlayer , QVideoWidget , QGraphicsVideoItem |
捕获音频和视频 | camera , recorder | CaptureSession , Camera , AudioInput VideoOutput | QMediaCaptureSession , QCamera , QAudioInput , QVideoWidget |
捕获照片 | camera , recorder | CaptureSession , Camera , ImageCapture | QMediaCaptureSession , QCamera , QImageCapture |
捕获影片 | camera , recorder | CaptureSession , Camera , MediaRecorder | QMediaCaptureSession , QCamera , QMediaRecorder |
The Qt Multimedia APIs build upon the multimedia framework of the underlying platform. This can mean that support for various codecs, or containers will vary between machines. This support depends on what the end user has installed. See 支持的媒体格式 for more detail.
注意: Qt Multimedia APIs depend on functionality provided by QCoreApplication , and multimedia objects created using the Qt Multimedia APIs can only be used during the lifetime of this application object. It is therefore important to create a QCoreApplication , QGuiApplication ,或 QApplication before accessing any of the Qt Multimedia APIs. If the application object is recreated, make sure that any Qt Multimedia objects are also recreated.
若之前在 Qt 5 中使用过 Qt Multimedia,见 Qt Multimedia 的变化 了解改变了什么的更多信息,及将代码移植到 Qt 6 时可能需要改变什么。