Phonon

mediaplayer-audio.cpp
1class MediaPlayer : public QMainWindow
2{
4 public:
5 MediaPlayer();
6
7 private slots:
8 void play(const QModelIndex &modelIndex);
9 void visEffectChanged(int index);
10
11 private:
12 QColumnView m_fileView;
13 QDirModel m_model;
14
15 Phonon::MediaObject *m_media;
16 Phonon::Visualization *m_vis;
17 QComboBox *m_visComboBox;
18};
19
20MediaPlayer::MediaPlayer()
21 : m_vis(0), m_visComboBox(0)
22{
23 //setCentralWidget(&m_fileView);
24 m_fileView.setModel(&m_model);
25 m_fileView.setFrameStyle(QFrame::NoFrame);
26
27 m_media = new MediaObject(this);
28 AudioOutput *output = new AudioOutput(Phonon::Music, this);
29 Phonon::createPath(m_media, output);
30
31 QList<VisualizationDescription> list = BackendCapabilities::availableVisualizationEffects();
32 if (!list.isEmpty()) {
33 VideoWidget *visWidget = new VideoWidget(this);
34 m_vis = new Visualization(this);
35 Phonon::createPath(m_media, m_vis);
36 Phonon::createPath(m_vis, visWidget);
37 m_vis->setVisualization(list.first());
38
39 m_visComboBox = new QComboBox(this);
40 m_visComboBox->setModel(new VisualizationDescriptionModel(list, m_visComboBox));
41 connect(m_visComboBox, SIGNAL(activated(int)), SLOT(visEffectChanged(int)));
42 }
43
44 connect(&m_fileView, SIGNAL(updatePreviewWidget(const QModelIndex &)), SLOT(play(const QModelIndex &)));
45}
46
47void MediaPlayer::play(const QModelIndex &modelIndex)
48{
49 m_media->setCurrentSource(url);
50 m_media->play();
51}
52
53void MediaPlayer::visEffectChanged(int index)
54{
55 QList<VisualizationDescription> list = BackendCapabilities::availableVisualizationEffects();
56 Q_ASSERT(index < list.size() && index >= 0);
57 m_vis->setVisualization(list.at(index));
58}
59
60
Interface for media playback of a given URL.
void setCurrentSource(const MediaSource &source)
Set the media source the MediaObject should use.
void play()
Requests playback of the media data to start.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const_reference at(qsizetype i) const const
T & first()
bool isEmpty() const const
qsizetype size() const const
Q_OBJECTQ_OBJECT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.