如何在我的声子媒体播放器中添加矩形?
现在这是一个基于声子(QT)的简单媒体播放器。
#include <QApplication>
#include <QWidget>
#include <phonon>
#include <QUrl>
#include <QObject>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget *widget = new QWidget;
widget->setWindowTitle("Media Player");
widget->resize(400,400);
Phonon::MediaObject *media = new Phonon::MediaObject;
media->setCurrentSource(Phonon::MediaSource("test.mpg"));
Phonon::VideoWidget *vwidget = new Phonon::VideoWidget(widget);
Phonon::createPath(media, vwidget);
vwidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto);
Phonon::AudioOutput *aOutput = new Phonon::AudioOutput(Phonon::VideoCategory);
Phonon::createPath(media, aOutput);
QLabel *label = new QLabel("Volume: ");
Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
volumeSlider->setAudioOutput(aOutput);
volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
Phonon::SeekSlider *seekSlider = new Phonon::SeekSlider;
seekSlider->setMediaObject(media);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(label);
hLayout->addWidget(volumeSlider);
hLayout->addStretch();
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(vwidget);
vLayout->addWidget(seekSlider);
vLayout->addLayout(hLayout);
widget->setLayout(vLayout);
widget->show();
media->play();
return app.exec();
}
现在我想在当前小部件播放视频时添加一些标志。我怎样才能实现这个? 例如,如果我想在当前帧的指定位置添加一个矩形。我怎么能这么做呢?
现在我又尝试这样做: 我定义了一个名为 MyVideoWidget 的类,它继承自 Phonon::VideoWidget。就像这样:
class MyVideoWidget : public Phonon::VideoWidget
然后我像这样重载函数paintEvent:
void
MyVideoWidget::paintEvent (QPaintEvent * event)
{
Phonon::VideoWidget::paintEvent (event);
QPainter painter (this);
QPen pen;
pen.setJoinStyle(Qt::MiterJoin);
pen.setWidth(5);
pen.setColor(QColor::fromRgb(255,255, 255));
painter.setPen(pen);
painter.drawLine (QPoint (20, 20), QPoint (100, 20));
painter.drawLine (QPoint (20, 100), QPoint (100, 100));
}
但仍然无法工作...... 有人有什么好主意吗?
Now This is a simple media player which is based on phonon(QT).
#include <QApplication>
#include <QWidget>
#include <phonon>
#include <QUrl>
#include <QObject>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget *widget = new QWidget;
widget->setWindowTitle("Media Player");
widget->resize(400,400);
Phonon::MediaObject *media = new Phonon::MediaObject;
media->setCurrentSource(Phonon::MediaSource("test.mpg"));
Phonon::VideoWidget *vwidget = new Phonon::VideoWidget(widget);
Phonon::createPath(media, vwidget);
vwidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto);
Phonon::AudioOutput *aOutput = new Phonon::AudioOutput(Phonon::VideoCategory);
Phonon::createPath(media, aOutput);
QLabel *label = new QLabel("Volume: ");
Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
volumeSlider->setAudioOutput(aOutput);
volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
Phonon::SeekSlider *seekSlider = new Phonon::SeekSlider;
seekSlider->setMediaObject(media);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(label);
hLayout->addWidget(volumeSlider);
hLayout->addStretch();
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(vwidget);
vLayout->addWidget(seekSlider);
vLayout->addLayout(hLayout);
widget->setLayout(vLayout);
widget->show();
media->play();
return app.exec();
}
And now I want to add some sign in the current widget when it is playing video. How can I implement this?
For example, if I want to add a rectangle in the specified position over the current frame. How could I do that?
Now I have another try to do this:
I define a class named MyVideoWidget which is inhred from Phonon::VideoWidget. Just like this:
class MyVideoWidget : public Phonon::VideoWidget
And then I overload the function paintEvent like this:
void
MyVideoWidget::paintEvent (QPaintEvent * event)
{
Phonon::VideoWidget::paintEvent (event);
QPainter painter (this);
QPen pen;
pen.setJoinStyle(Qt::MiterJoin);
pen.setWidth(5);
pen.setColor(QColor::fromRgb(255,255, 255));
painter.setPen(pen);
painter.drawLine (QPoint (20, 20), QPoint (100, 20));
painter.drawLine (QPoint (20, 100), QPoint (100, 100));
}
But is still cannot work...
Does anyone has some good idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我的选择中,我根本不会触及声子的实现。我会使用 QStackedLayout 创建一个覆盖层,而不是尝试重新实现 Phonon::VideoWidget。这是修改后的示例
}
In my option I would not touch Phonon implementation at all. Rather then trying to re-implement the Phonon::VideoWidget I would create an overlay using QStackedLayout. here is your example modified
}