媒體播放器範例

播放音頻和視頻。

媒體播放器 演示可以使用各種編解碼器播放音頻和或視頻文件的簡單多媒體播放器。

運行範例

要運行範例從 Qt Creator ,打開 歡迎 模式,然後選擇範例從 範例 。更多信息,拜訪 構建和運行範例 .

範例使用 QMediaPlayer 對象被傳入 QVideoWidget 以控製視頻輸齣。為賦予應用程序播放列錶能力,還使用瞭 QPlayList 對象。

為激活對話框中 (譬如:播放和停止) 各種功能,按鈕點擊事件要發射 play() 和 stop() 信號並連接到 play() 和 stop() 槽對於 QMediaPlayer .

connect(controls, SIGNAL(play()), player, SLOT(play()));
connect(controls, SIGNAL(pause()), player, SLOT(pause()));
connect(controls, SIGNAL(stop()), player, SLOT(stop()));
					

可以獲取音量 (並設置用戶界麵錶示)

controls->setVolume(player->volume());
					

可以讓 Widget 更改 volume 以改變音量

connect(controls, SIGNAL(changeVolume(int)), player, SLOT(setVolume(int)));
					

The example also allows us to change various video properties by means of the QVideoWidget object. We can go to Full Screen mode with a single button click, and back again. Or if we press the "Color Options" dialog button we can have access to more subtle influences. The dialog has a set of sliders so that we can change the brightness, contrast, hue and saturation of the video being watched. The connect() statements are in pairs so that changes to either the user interface widget (the relevant slider) or the QVideoWidget 對象將更新其它對象。

connect(brightnessSlider, SIGNAL(sliderMoved(int)), videoWidget,
    SLOT(setBrightness(int)));
connect(videoWidget, SIGNAL(brightnessChanged(int)),
    brightnessSlider, SLOT(setValue(int)));
connect(contrastSlider, SIGNAL(sliderMoved(int)), videoWidget,
    SLOT(setContrast(int)));
connect(videoWidget, SIGNAL(contrastChanged(int)), contrastSlider,
    SLOT(setValue(int)));
connect(hueSlider, SIGNAL(sliderMoved(int)), videoWidget,
    SLOT(setHue(int)));
connect(videoWidget, SIGNAL(hueChanged(int)), hueSlider,
    SLOT(setValue(int)));
connect(saturationSlider, SIGNAL(sliderMoved(int)), videoWidget,
    SLOT(setSaturation(int)));
connect(videoWidget, SIGNAL(saturationChanged(int)),
    saturationSlider, SLOT(setValue(int)));
					

範例工程 @ code.qt.io