-rw-r--r-- | library/sound.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/library/sound.cpp b/library/sound.cpp index 602fcf0..1ff3b3f 100644 --- a/library/sound.cpp +++ b/library/sound.cpp @@ -98,96 +98,101 @@ static int WAVsoundDuration(const QString& filename) //qDebug("%dms",total); return total; } class SoundData : public QSound { public: SoundData(const QString& name) : QSound(Resource::findSound(name)), filename(Resource::findSound(name)) { loopsleft=0; + ms = WAVsoundDuration(filename); } void playLoop(int loopcnt = -1) { // needs server support loopsleft = loopcnt; - int ms = WAVsoundDuration(filename); if ( ms ) startTimer(ms > 50 ? ms-50 : 0); // 50 for latency play(); } void timerEvent ( QTimerEvent *e ) { if (loopsleft >= 0) { - if (--loopsleft <= 0) + if ( --loopsleft <= 0 ) { killTimer (e->timerId()); + loopsleft = 0; return; } + } play(); } bool isFinished ( ) const { return ( loopsleft == 0 ); } private: QString filename; int loopsleft; + int ms; }; + #endif Sound::Sound(const QString& name) { #ifndef QT_NO_SOUND d = new SoundData(name); #endif } Sound::~Sound() { #ifndef QT_NO_SOUND delete d; #endif } void Sound::play() { #ifndef QT_NO_SOUND - d->killTimers(); d->playLoop(1); #endif } void Sound::playLoop() { #ifndef QT_NO_SOUND d->killTimers(); d->playLoop(); #endif } void Sound::stop() { #ifndef QT_NO_SOUND d->killTimers(); #endif } bool Sound::isFinished() const { #ifndef QT_NO_SOUND return d->isFinished(); +#else + return true; #endif } void Sound::soundAlarm() { #ifndef QT_NO_COP QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); #endif } |