File indexing completed on 2024-05-12 04:44:40

0001 #include <QMainWindow>
0002 
0003 class MediaPlayer : public QMainWindow
0004 {
0005     Q_OBJECT
0006     public:
0007         MediaPlayer();
0008 
0009     private slots:
0010         void play(const QModelIndex &modelIndex);
0011         void visEffectChanged(int index);
0012 
0013     private:
0014         QColumnView m_fileView;
0015         QDirModel m_model;
0016 
0017         Phonon::MediaObject *m_media;
0018         Phonon::Visualization *m_vis;
0019         Phonon::SubtitleStreamDescriptionModel m_subtitleModel;
0020         QComboBox *m_visComboBox;
0021 };
0022 
0023 MediaPlayer::MediaPlayer()
0024     : m_vis(0), m_visComboBox(0)
0025 {
0026     //setCentralWidget(&m_fileView);
0027     m_fileView.setModel(&m_model);
0028     m_fileView.setFrameStyle(QFrame::NoFrame);
0029 
0030     m_media = new MediaObject(this);
0031 
0032     AudioPath *apath = new AudioPath(this);
0033     AudioOutput *aoutput = new AudioOutput(Phonon::Music, this);
0034     m_media->addAudioPath(apath);
0035     apath->addOutput(aoutput);
0036 
0037     VideoPath *vpath = new VideoPath(this);
0038     VideoWidget *vwidget = new VideoWidget(this);
0039     m_media->addVideoPath(vpath);
0040     vpath->addOutput(vwidget);
0041 
0042     // the following signal does not exist yet, but should, IMHO:
0043     connect(m_media, SIGNAL(availableSubtitleStreamsChanged()), SLOT(updateSubtitleSelector()));
0044 
0045     m_subtitleSelector = new QListView(this);
0046     m_subtitleSelector->setModel(&m_subtitleModel);
0047     connect(m_subtitleSelector, SIGNAL(activated(const QModelIndex &)), SLOT(changeSubtitle(const QModelIndex &)));
0048 
0049     connect(&m_fileView, SIGNAL(updatePreviewWidget(const QModelIndex &)), SLOT(play(const QModelIndex &)));
0050 }
0051 
0052 void MediaPlayer::play(const QModelIndex &modelIndex)
0053 {
0054     m_media->setCurrentSource(url);
0055     m_media->play();
0056 }
0057 
0058 void MediaPlayer::updateSubtitleSelector()
0059 {
0060     QList<SubtitleStreamDescription> list = m_media->availableSubtitleStreams();
0061     m_subtitleModel.setModelData(list);
0062 }
0063 
0064 void MediaPlayer::changeSubtitle(const QModelIndex &modelIndex)
0065 {
0066     const int index = modelIndex.row();
0067     QList<SubtitleStreamDescription> list = m_media->availableSubtitleStreams();
0068     Q_ASSERT(index < list.size() && index >= 0);
0069     m_media->setCurrentSubtitleStream(list.at(index));
0070 }