QT5 中怎么用metadata获取视频文件信息?

KAKASI 2013-10-15 10:38:28
....
connect(&mediaPlayer, SIGNAL(metaDataChanged()), this, SLOT(getInformation()));
....
void VideoPlayer::getInformation()
{
if ( mediaPlayer.isMetaDataAvailable())
{
titleLabel->setText(mediaPlayer.metaData(QMediaMetaData::Title).toString());
}
}

一直获取不到?
请达人帮忙看下.
...全文
940 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
一去丶二三里 2013-10-21
  • 打赏
  • 举报
回复
引用 3 楼 tempofwyq 的回复:
看来不能纠结在这了,先寻找第三方库解决这个问题.
taglib 试试 或者 QtAV、FFMpeg
KAKASI 2013-10-20
  • 打赏
  • 举报
回复
有play(),还是取不到,换了meta-data keys也取不到. 源码: #include "playertest.h" //#include <QtWidgets> //UI元素头文件 #include <QAbstractButton> #include <QPushButton> #include <QSlider> #include <QLabel> #include <QStyle> #include <QHBoxLayout> #include <QVBoxLayout> #include <QFileDialog> #include <QDir> #include <QVideoWidget> //视频窗体头文件 #include <QVideoSurfaceFormat> // #include <QMediaMetaData> #include <QDebug> VideoPlayer::VideoPlayer(QWidget *parent) : QWidget(parent) //, mediaPlayer(0, QMediaPlayer::VideoSurface) , playButton(0) , positionSlider(0) , infoLabel(0) { mediaPlayer = new QMediaPlayer(this); QVideoWidget *videoWidget = new QVideoWidget; //视频窗口 videoWidget->setFullScreen(true);//全屏 QAbstractButton *openButton = new QPushButton(tr("Open...")); connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); playButton = new QPushButton; playButton->setEnabled(false); playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); connect(playButton, SIGNAL(clicked()), this, SLOT(play())); positionSlider = new QSlider(Qt::Horizontal); positionSlider->setRange(0, 0); connect(positionSlider, SIGNAL(sliderMoved(int)), this, SLOT(setPosition(int))); infoLabel = new QLabel; infoLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); QBoxLayout *controlLayout = new QHBoxLayout; controlLayout->setMargin(0); controlLayout->addWidget(openButton); controlLayout->addWidget(playButton); controlLayout->addWidget(positionSlider); QBoxLayout *layout = new QVBoxLayout; layout->addWidget(videoWidget); layout->addLayout(controlLayout); layout->addWidget(infoLabel); setLayout(layout); //setWindowFlags(Qt::FramelessWindowHint); //无标题栏 mediaPlayer->setVideoOutput(videoWidget); connect(mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(mediaStateChanged(QMediaPlayer::State))); connect(mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64))); connect(mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(durationChanged(qint64))); connect(mediaPlayer, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(handleError())); connect(mediaPlayer, SIGNAL(metaDataChanged()), this, SLOT(getInformation()), Qt::QueuedConnection); } VideoPlayer::~VideoPlayer() { } void VideoPlayer::openFile() { infoLabel->setText(""); QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),QDir::homePath()); if (!fileName.isEmpty()) { mediaPlayer->setMedia(QUrl::fromLocalFile(fileName)); playButton->setEnabled(true); } } void VideoPlayer::play() { switch(mediaPlayer->state()) { case QMediaPlayer::PlayingState: mediaPlayer->pause(); break; default: mediaPlayer->play(); break; } } void VideoPlayer::mediaStateChanged(QMediaPlayer::State state) { switch(state) { case QMediaPlayer::PlayingState: playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); break; default: playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); break; } } void VideoPlayer::positionChanged(qint64 position) { positionSlider->setValue(position); this->setWindowTitle(tr("%1").arg(position/1000)); } void VideoPlayer::durationChanged(qint64 duration) { positionSlider->setRange(0, duration); //errorLabel->setText(tr("%1").arg(duration/1000)); //errorLabel->setText(mediaPlayer.metaData(QMediaMetaData::).toString()); } void VideoPlayer::setPosition(int position) { mediaPlayer->setPosition(position); } void VideoPlayer::handleError() { playButton->setEnabled(false); infoLabel->setText("Error: " + mediaPlayer->errorString()); } void VideoPlayer::getInformation() { if ( mediaPlayer->isMetaDataAvailable()) { infoLabel->setText(mediaPlayer->metaData(QMediaMetaData::Resolution).toString()); qDebug()<<"info1:"<<mediaPlayer->metaData(QMediaMetaData::Resolution).toString(); } else { //qDebug("isMetaDataAvailable = false"); qDebug()<<"info2:"<<mediaPlayer->metaData(QMediaMetaData::Resolution).toString(); } }
KAKASI 2013-10-20
  • 打赏
  • 举报
回复
看来不能纠结在这了,先寻找第三方库解决这个问题.
一去丶二三里 2013-10-16
  • 打赏
  • 举报
回复
你把视频播放一下,就可以获得了!play

16,201

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧