phonon 播放视频
#include <QtGui>
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <Phonon/MediaObject>
#include <Phonon/VideoPlayer>
#include <Phonon/BackendCapabilities>
#include <QUrl>
MyPlayer::MyPlayer(QWidget *parent) :
QDialog(parent),
ui(new Ui::MyPlayer)
{
ui->setupUi(this);
}
//home/projects/QTmplayer-build-desktop/../QTmplayer/myplayer.cpp:4: error: QPhonon: 没有那个文件或目录
MyPlayer::~MyPlayer()
{
delete ui;
}
void MyPlayer::on_playStart_clicked()
{
QWidget *widget = new QWidget;
widget->setWindowTitle("Media Player");
widget->resize(700,600);
Phonon::MediaObject *media = new Phonon::MediaObject;
media->setCurrentSource(Phonon::MediaSource("XMuMing.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();
/*
this->setWindowTitle("my test video player");
Phonon::VideoPlayer *player = new Phonon::VideoPlayer(Phonon::VideoCategory, ui->widget);
player->load(Phonon::MediaSource("/home/video/XMuMing.mpg"));
player->play();
Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(this);
Phonon::createPath(mediaObject, videoWidget);
Phonon::AudioOutput *audioOutput=new Phonon::AudioOutput(Phonon::VideoCategory, this);
Phonon::createPath(mediaObject, audioOutput);
mediaObject->setCurrentSource(Phonon::MediaSource("D:\\001.wmv"));
mediaObject->play();
Phonon::MediaObject *music =
Phonon::createPlayer(Phonon::MusicCategory,
Phonon::MediaSource("/home/video/caiyan.rmvb"));
music->play();
Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
mediaObject->setCurrentSource(Phonon::MediaSource("/mymusic/barbiegirl.wav"));
Phonon::AudioOutput *audioOutput =
new Phonon::AudioOutput(Phonon::MusicCategory, this);
Phonon::Path path = Phonon::createPath(mediaObject, audioOutput);
//视频播放
Phonon::MediaObject *music =
Phonon::createPlayer(Phonon::VideoCategory,
Phonon::MediaSource("/home/video/caiyan.rmvb"));
music->play();
*/
//label = new QLabel(this);
//label->setScaledContents(true);
// movie = new QMovie("tp.gif");
//label->setMovie(movie);
// movie->start();
}
运行还是播放不了视频,要按转ffmpeg解码库才行。
sudo apt-get install libxine1-ffmpeg