QT QMediaPlayer播放器

注:使用QMediaPlayer需要在项目文件.pro加入

  1. QT += multimedia

  2. QT += multimediawidgets

代码:

QVBoxLayout *layout = new QVBoxLayout;

    QVideoWidget* videoWidget = new QVideoWidget;

//    QMediaPlaylist* playlist=new QMediaPlaylist;

    layout->addWidget(videoWidget);

    ui->widget->setLayout(layout);

    player=new QMediaPlayer();

    QFile file("C:/video.mp4");

扫描二维码关注公众号,回复: 8894890 查看本文章

    if(!file.open(QIODevice::ReadOnly))

        qDebug() << "Could not open file";

    player->setMedia(QUrl::fromLocalFile("C:/v2.mp4"));

    player->setVideoOutput(videoWidget);

//    player->setPlaylist(playlist);

//    connect(player, SIGNAL(videoAvailableChanged(bool)), this, SLOT(VideoAvaildableChange(bool)));

    videoWidget->show();

//    ui->widget->showFullScreen();

    player->play();

//    player->setVolume(50);

发布了18 篇原创文章 · 获赞 1 · 访问量 2183

猜你喜欢

转载自blog.csdn.net/leng3667/article/details/102897095