
使用phonon来做播放器非常简单。
http://www.diybl.com/course/3_program/c++/cppjs/20091228/185844.html
亮点:
|
02 |
|
03 |
#include <QApplication> |
|
04 |
#include <QWidget> |
|
05 |
|
06 |
#include <Phonon/MediaObject> |
|
07 |
#include <Phonon/VideoWidget> |
|
08 |
#include <Phonon/AudioOutput> |
|
09 |
#include <QUrl> |
|
10 |
#include <QObject> |
|
11 |
#include <QVBoxLayout> |
|
12 |
#include <QHBoxLayout> |
|
13 |
#include <QLabel> |
|
14 |
#include <Phonon/VolumeSlider> |
|
15 |
#include <Phonon/SeekSlider> |
|
16 |
|
17 |
int main(int argc, char *argv[]) { |
|
18 |
QApplication app(argc, argv); |
|
19 |
|
20 |
QWidget *widget = new QWidget; |
|
21 |
widget->setWindowTitle("Media Player"); |
|
22 |
widget->resize(400,400); |
|
23 |
|
24 |
Phonon::MediaObject *media = new Phonon::MediaObject; |
|
25 |
media->setCurrentSource(Phonon::MediaSource("fable.avi")); |
|
26 |
|
27 |
Phonon::VideoWidget *vwidget = new Phonon::VideoWidget(widget); |
|
28 |
Phonon::createPath(media, vwidget); |
|
29 |
vwidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto); |
|
30 |
Phonon::AudioOutput *aOutput = new Phonon::AudioOutput(Phonon::VideoCategory); |
|
31 |
Phonon::createPath(media, aOutput); |
|
32 |
|
33 |
QLabel *label = new QLabel("Volume: "); |
|
34 |
Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider; |
|
35 |
volumeSlider->setAudioOutput(aOutput); |
|
36 |
volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
37 |
|
38 |
Phonon::SeekSlider *seekSlider = new Phonon::SeekSlider; |
|
39 |
seekSlider->setMediaObject(media); |
|
40 |
|
41 |
QHBoxLayout *hLayout = new QHBoxLayout; |
|
42 |
hLayout->addWidget(label); |
|
43 |
hLayout->addWidget(volumeSlider); |
|
44 |
hLayout->addStretch(); |
|
45 |
|
46 |
QVBoxLayout *vLayout = new QVBoxLayout; |
|
47 |
vLayout->addWidget(vwidget); |
|
48 |
vLayout->addWidget(seekSlider); |
|
49 |
vLayout->addLayout(hLayout); |
|
50 |
|
51 |
widget->setLayout(vLayout); |
|
52 |
|
53 |
widget->show(); |
|
54 |
media->play(); |
|
55 |
return app.exec(); |
|
56 |
} |
HxLauncher: Launch Android applications by voice commands