qt弹出对话框选择视频并播放

来源:互联网 发布:淘宝代理商怎么找 编辑:程序博客网 时间:2024/05/19 06:46
 QString path = QFileDialog::getOpenFileName(this, tr("选择视频"), ".", tr("Image Files(*.mp4)"));//得到视频路径    mediaPlayer = new QMediaPlayer();    videoWidget = new QVideoWidget();    this->setCentralWidget(videoWidget);     //给VideoWidget画上黑色的背景,这样会更专业点(默认是灰白色的)     QPalette* palette = new QPalette();     palette->setBrush(QPalette::Background, Qt::black);     videoWidget->setPalette(*palette);     videoWidget->setAutoFillBackground(true);     delete palette;     /*     设置播放视频的比例     enum AspectRatioMode {         IgnoreAspectRatio,         KeepAspectRatio,         KeepAspectRatioByExpanding     };      */     videoWidget->setAspectRatioMode(Qt::IgnoreAspectRatio);//保持比例     mediaPlayer->setVideoOutput(videoWidget);     //第一种方法:mediaPlayer直接setMedia()     mediaPlayer->setMedia(QUrl::fromLocalFile(path));     mediaPlayer->play();
原创粉丝点击