1
/***************************************************************************
2
* Copyright 2011 Stefan Majewsky <majewsky@gmx.net> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU Library General Public License *
6
* version 2 as published by the Free Software Foundation *
8
* This program is distributed in the hope that it will be useful, *
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11
* GNU Library General Public License for more details. *
13
* You should have received a copy of the GNU Library General Public *
14
* License along with this program; if not, write to the *
15
* Free Software Foundation, Inc., *
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
17
***************************************************************************/
21
#include <Phonon/MediaObject>
24
class KgSound::Private
29
qint64 m_lastPlayedTime;
31
Phonon::MediaObject* m_sound1;
32
Phonon::MediaObject* m_sound2;
34
Private() : m_volume(1.0), m_valid(false), m_lastPlayedTime(0), m_nextSource(1), m_sound1(NULL), m_sound2(NULL) {}
45
KgSound::KgSound(const QString& file, QObject* parent)
49
d->m_sound1 = Phonon::createPlayer(Phonon::GameCategory);
50
d->m_sound1->setCurrentSource(file);
51
d->m_sound2 = Phonon::createPlayer(Phonon::GameCategory);
52
d->m_sound2->setCurrentSource(file);
53
d->m_valid = d->m_sound1->isValid() && d->m_sound2->isValid();
61
bool KgSound::isValid() const
66
KgSound::PlaybackType KgSound::playbackType() const
68
return KgSound::AmbientPlayback;
71
void KgSound::setPlaybackType(KgSound::PlaybackType type)
76
QPointF KgSound::pos() const
78
return QPointF(0.0, 0.0);
81
void KgSound::setPos(const QPointF& pos)
86
qreal KgSound::volume() const
92
void KgSound::setVolume(qreal volume)
97
bool KgSound::hasError() const
99
if (d->m_sound1 && d->m_sound1->state() == Phonon::ErrorState)
103
if (d->m_sound2 && d->m_sound2->state() == Phonon::ErrorState)
110
void KgSound::start()
112
if(!d->m_sound1 || !d->m_sound2)
117
QDateTime now = QDateTime::currentDateTime();
118
qint64 timeNow = now.toTime_t() * 1000 + now.time().msec();
120
if(timeNow - d->m_lastPlayedTime > 20)
122
if(d->m_nextSource == 1)
124
if(d->m_sound1->state() == Phonon::StoppedState)
136
if(d->m_sound2->state() == Phonon::StoppedState)
146
d->m_lastPlayedTime = timeNow;
150
void KgSound::start(const QPointF& pos)
159
if(!d->m_sound1 || !d->m_sound2)
168
#include "kgsound.moc"