qt弹出对话框选择视频并播放
2017-09-27 19:21
405 查看
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();
相关文章推荐
- 安卓开发:弹出自定义对话框自动播放视频(仿视频广告效果,使用mediaplayer和surfaceview做播放器)
- cocos2d-x 弹出对话框播放视频
- 【QT】视频播放+文件选择
- qt弹出对话框选择图片并显示
- Android 选择日期时间对话框(可选择开始结束时间,已解决弹出键盘问题)
- Qt 调用phonon 在xp下不能播放视频的解决方法(Phonon::createPath: Cannot connect Phonon::MediaObject ( no objectName )...)
- MFC中弹出选择文件夹的对话框 BROWSEINFO 的用法
- Window 下 Qt5 使用QMediaplayer 进行视频播放 流播放问题
- C# winform 窗体弹出选择目录或文件 的对话框
- MFC下面弹出一个选择文件夹对话框
- 自学QT之从对话框弹出对话框
- 弹出选择文件夹的对话框 BROWSEINFO 的用法【MFC】
- DataGrid中全选删除按钮,如果没选,先提示没有选择,再弹出确定删除对话框的例子
- Qt弹出一个对话框
- summernote 文本编辑器使用时,选择上传图片、链接、录像时,弹出的对话框被遮挡住
- QT QMediaPlayer 播放音视频文件
- QT5入门之17 - 文件选择对话框
- 点击文本框时弹出单选(或复选)对话框,选择选项后在文本框中显示
- QT选择文件对话框实现多种类型文件匹配过滤
- 关于VC弹出选择文件夹对话框