From: Peter Penz Date: Sat, 31 Jan 2009 13:04:40 +0000 (+0000) Subject: Postpone the creating of the media object until the play- or stop-button has been... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/e5edeb7446c0ec60d0962fb5cd0077c374a472ef Postpone the creating of the media object until the play- or stop-button has been pressed. This solves the issue that Dolphin might get blocked during hovering media files. Dolphin still gets blocked when requesting a media object the first time, but for the user this "just" means that after pressing the play-button the first time, that the playing starts a little bit later. CCMAIL: kretz@kde.org CCMAIL: kdedevel@etotheipiplusone.com svn path=/trunk/KDE/kdebase/apps/; revision=919063 --- diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp index d52ae9d8a..d27b78a3c 100644 --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -31,7 +31,11 @@ PhononWidget::PhononWidget(QWidget *parent) : QWidget(parent), - m_media(0) + m_url(), + m_playButton(0), + m_stopButton(0), + m_media(0), + m_seekSlider(0) { QHBoxLayout *innerLayout = new QHBoxLayout(this); innerLayout->setMargin(0); @@ -46,24 +50,22 @@ PhononWidget::PhononWidget(QWidget *parent) m_playButton->setToolTip(i18n("play")); m_playButton->setIconSize(QSize(16, 16)); m_playButton->setIcon(KIcon("media-playback-start")); + connect(m_playButton, SIGNAL(clicked()), this, SLOT(play())); + m_stopButton->setToolTip(i18n("stop")); m_stopButton->setIconSize(QSize(16, 16)); m_stopButton->setIcon(KIcon("media-playback-stop")); m_stopButton->hide(); + connect(m_stopButton, SIGNAL(clicked()), this, SLOT(stop())); + m_seekSlider->setIconVisible(false); } void PhononWidget::setUrl(const KUrl &url) { + m_url = url; if (m_media) { m_media->setCurrentSource(url); - } else { - m_media = Phonon::createPlayer(Phonon::MusicCategory, url); - m_media->setParent(this); - connect(m_playButton, SIGNAL(clicked()), m_media, SLOT(play())); - connect(m_stopButton, SIGNAL(clicked()), m_media, SLOT(stop())); - connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State))); - m_seekSlider->setMediaObject(m_media); } } @@ -83,3 +85,26 @@ void PhononWidget::stateChanged(Phonon::State newstate) } setUpdatesEnabled(true); } + +void PhononWidget::play() +{ + requestMedia(); + m_media->play(); +} + +void PhononWidget::stop() +{ + requestMedia(); + m_media->stop(); +} + +void PhononWidget::requestMedia() +{ + if (!m_media) { + m_media = Phonon::createPlayer(Phonon::MusicCategory, m_url); + m_media->setParent(this); + connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State))); + m_seekSlider->setMediaObject(m_media); + } +} + diff --git a/src/panels/information/phononwidget.h b/src/panels/information/phononwidget.h index 5c43e7e49..320ecbe6d 100644 --- a/src/panels/information/phononwidget.h +++ b/src/panels/information/phononwidget.h @@ -21,6 +21,8 @@ #ifndef PHONONWIDGET_H #define PHONONWIDGET_H +#include + #include #include @@ -32,7 +34,6 @@ namespace Phonon } // namespace Phonon class QToolButton; -class KUrl; class PhononWidget : public QWidget { @@ -43,8 +44,14 @@ class PhononWidget : public QWidget private slots: void stateChanged(Phonon::State); + void play(); + void stop(); + + private: + void requestMedia(); private: + KUrl m_url; QToolButton *m_playButton; QToolButton *m_stopButton; Phonon::MediaObject *m_media;