diff options
author | Justin McPherson <justin.mcpherson@nokia.com> | 2010-03-08 03:45:33 (GMT) |
---|---|---|
committer | Justin McPherson <justin.mcpherson@nokia.com> | 2010-03-08 05:53:08 (GMT) |
commit | 2e501c4d45dddba3db2d8817a27380615c1ce8fd (patch) | |
tree | 89598b65b64a0425868e8335e794ba380330fab9 /src/multimedia/effects/qsoundeffect_qmedia_p.cpp | |
parent | a8b5200403742272811f095c0710193a27eed466 (diff) | |
download | Qt-2e501c4d45dddba3db2d8817a27380615c1ce8fd.zip Qt-2e501c4d45dddba3db2d8817a27380615c1ce8fd.tar.gz Qt-2e501c4d45dddba3db2d8817a27380615c1ce8fd.tar.bz2 |
Refactor QSoundEffect.
Reviewed-by: Dmytro Poplavskiy
Diffstat (limited to 'src/multimedia/effects/qsoundeffect_qmedia_p.cpp')
-rw-r--r-- | src/multimedia/effects/qsoundeffect_qmedia_p.cpp | 99 |
1 files changed, 36 insertions, 63 deletions
diff --git a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp b/src/multimedia/effects/qsoundeffect_qmedia_p.cpp index 48fb257..e670a36 100644 --- a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp +++ b/src/multimedia/effects/qsoundeffect_qmedia_p.cpp @@ -50,117 +50,90 @@ // We mean it. // -#include <QtCore/qcoreapplication.h> +#include "qsoundeffect_qmedia_p.h" -#include "qmediacontent.h" -#include "qmediaplayer.h" +#include <QtCore/qcoreapplication.h> -#include "qsoundeffect_p.h" -#include "qsoundeffect_qmedia_p.h" +#include <QtMultimedia/qmediacontent.h> +#include <QtMultimedia/qmediaplayer.h> QT_BEGIN_NAMESPACE QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): QObject(parent), - m_muted(false), - m_vol(100), + m_loopCount(1), + m_runningCount(0), m_player(0) { + m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); + connect(m_player, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged())); + connect(m_player, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged())); + connect(m_player, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged())); + connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(stateChanged(QMediaPlayer::State))); } QSoundEffectPrivate::~QSoundEffectPrivate() { - if (m_player) delete m_player; } -qint64 QSoundEffectPrivate::duration() const +QUrl QSoundEffectPrivate::source() const { - if (m_player) return m_player->duration(); - - return 0; + return m_player->media().canonicalUrl(); } -int QSoundEffectPrivate::volume() const +void QSoundEffectPrivate::setSource(const QUrl &url) { - if (m_player) return m_player->volume(); - - return m_vol; + m_player->setMedia(url); } -bool QSoundEffectPrivate::isMuted() const +int QSoundEffectPrivate::loopCount() const { - if (m_player) return m_player->isMuted(); - - return m_muted; + return m_loopCount; } -QMediaContent QSoundEffectPrivate::media() const +void QSoundEffectPrivate::setLoopCount(int loopCount) { - if (m_player) return m_player->media(); - - return QMediaContent(); + m_loopCount = loopCount; } -QMediaPlayer::State QSoundEffectPrivate::state() const +int QSoundEffectPrivate::volume() const { - if (m_player) return m_player->state(); - - return QMediaPlayer::StoppedState; + return m_player->volume(); } -QMediaPlayer::MediaStatus QSoundEffectPrivate::mediaStatus() const +void QSoundEffectPrivate::setVolume(int volume) { - if (m_player) return m_player->mediaStatus(); - - return QMediaPlayer::UnknownMediaStatus; + m_player->setVolume(volume); } -void QSoundEffectPrivate::play() +bool QSoundEffectPrivate::isMuted() const { - if (m_player && !m_player->isMuted()) - m_player->play(); + return m_player->isMuted(); } -void QSoundEffectPrivate::stop() +void QSoundEffectPrivate::setMuted(bool muted) { - if (m_player) - m_player->stop(); + m_player->setMuted(muted); } -void QSoundEffectPrivate::setVolume(int volume) +int QSoundEffectPrivate::duration() const { - m_vol = volume; - - if (m_player) - m_player->setVolume(volume); + return m_player->duration(); } -void QSoundEffectPrivate::setMuted(bool muted) +void QSoundEffectPrivate::play() { - m_muted = muted; - - if (m_player) - m_player->setMuted(muted); + m_runningCount += m_loopCount; + m_player->play(); } -void QSoundEffectPrivate::setMedia(const QMediaContent &media) +void QSoundEffectPrivate::stateChanged(QMediaPlayer::State state) { - if (media.isNull()) - return; - - if (m_player == 0) { - m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); - m_player->setVolume(m_vol); - m_player->setMuted(m_muted); - - connect(m_player, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); - connect(m_player, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); - connect(m_player, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64))); - connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SIGNAL(stateChanged(QMediaPlayer::State))); + if (state == QMediaPlayer::StoppedState) { + if (--m_runningCount > 0) + m_player->play(); } - - m_player->setMedia(media.canonicalUrl()); } QT_END_NAMESPACE |