Phonon

mediaplayer-video.cpp
1#include <QMainWindow>
2
3class MediaPlayer : public QMainWindow
4{
6 public:
7 MediaPlayer();
8
9 private slots:
10 void play(const QModelIndex &modelIndex);
11 void visEffectChanged(int index);
12
13 private:
14 QColumnView m_fileView;
15 QDirModel m_model;
16
17 Phonon::MediaObject *m_media;
18 Phonon::Visualization *m_vis;
19 Phonon::SubtitleStreamDescriptionModel m_subtitleModel;
20 QComboBox *m_visComboBox;
21};
22
23MediaPlayer::MediaPlayer()
24 : m_vis(0), m_visComboBox(0)
25{
26 //setCentralWidget(&m_fileView);
27 m_fileView.setModel(&m_model);
28 m_fileView.setFrameStyle(QFrame::NoFrame);
29
30 m_media = new MediaObject(this);
31
32 AudioPath *apath = new AudioPath(this);
33 AudioOutput *aoutput = new AudioOutput(Phonon::Music, this);
34 m_media->addAudioPath(apath);
35 apath->addOutput(aoutput);
36
37 VideoPath *vpath = new VideoPath(this);
38 VideoWidget *vwidget = new VideoWidget(this);
39 m_media->addVideoPath(vpath);
40 vpath->addOutput(vwidget);
41
42 // the following signal does not exist yet, but should, IMHO:
43 connect(m_media, SIGNAL(availableSubtitleStreamsChanged()), SLOT(updateSubtitleSelector()));
44
45 m_subtitleSelector = new QListView(this);
46 m_subtitleSelector->setModel(&m_subtitleModel);
47 connect(m_subtitleSelector, SIGNAL(activated(const QModelIndex &)), SLOT(changeSubtitle(const QModelIndex &)));
48
49 connect(&m_fileView, SIGNAL(updatePreviewWidget(const QModelIndex &)), SLOT(play(const QModelIndex &)));
50}
51
52void MediaPlayer::play(const QModelIndex &modelIndex)
53{
54 m_media->setCurrentSource(url);
55 m_media->play();
56}
57
58void MediaPlayer::updateSubtitleSelector()
59{
60 QList<SubtitleStreamDescription> list = m_media->availableSubtitleStreams();
61 m_subtitleModel.setModelData(list);
62}
63
64void MediaPlayer::changeSubtitle(const QModelIndex &modelIndex)
65{
66 const int index = modelIndex.row();
67 QList<SubtitleStreamDescription> list = m_media->availableSubtitleStreams();
68 Q_ASSERT(index < list.size() && index >= 0);
69 m_media->setCurrentSubtitleStream(list.at(index));
70}
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
qsizetype size() const const
int row() 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 Fri Oct 11 2024 12:10:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.