现在这是一个基于声子(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));
}
但仍然无法工作......有人有什么好主意吗?