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
This commit is contained in:
Peter Penz 2009-01-31 13:04:40 +00:00
parent 68a7ed8bcf
commit e5edeb7446
2 changed files with 41 additions and 9 deletions

View file

@ -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);
}
}

View file

@ -21,6 +21,8 @@
#ifndef PHONONWIDGET_H
#define PHONONWIDGET_H
#include <kurl.h>
#include <QtGui/QWidget>
#include <Phonon/Global>
@ -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;