播放音频和视频。
媒体播放器 演示可以使用各种编解码器播放音频和或视频文件的简单多媒体播放器。
要运行范例从 Qt Creator ,打开 Welcome 模式,然后选择范例从 Examples 。更多信息,拜访 构建和运行范例 .
范例使用 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 video properties by means of the QVideoWidget object. We can go to Full Screen mode with a single button click, and back again.