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 | |
| 訪問原生音頻輸入數據 | 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 時可能需要改變什麼。