视频播放的关键代码如下:
使用Qt6的QMediaPlayer,QVideoWidget实现
void FunnyWidget::initVideo()
{
player = new QMediaPlayer(this);
videoWidget = new QVideoWidget(this);
playButton = new QPushButton("Play", this);
pauseButton = new QPushButton("Pause", this);
stopButton = new QPushButton("Stop", this);
// 设置视频输出
player->setVideoOutput(videoWidget);
// 设置按钮布局
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(playButton);
buttonLayout->addWidget(pauseButton);
buttonLayout->addWidget(stopButton);
// 主窗口布局
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(videoWidget);
mainLayout->addLayout(buttonLayout);
QWidget *centralWidget = new QWidget;