From 355645922bab394eaeff6bc17297f784f55aff06 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 5 Feb 2007 15:26:05 +0000 Subject: [PATCH] Make the playback of repeating sounds working (hopefully). Add a way to stop all the playbacks of the AudioPlayer. svn path=/trunk/playground/graphics/okular/; revision=630500 --- core/audioplayer.cpp | 37 +++++++++++++++++++++++++++++++++---- core/audioplayer.h | 5 +++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/core/audioplayer.cpp b/core/audioplayer.cpp index a0036f5eb..c6a5b51c5 100644 --- a/core/audioplayer.cpp +++ b/core/audioplayer.cpp @@ -57,6 +57,18 @@ public: { } + void play() + { + if ( m_mediaobject ) + { + m_mediaobject->play(); + } + else if ( m_bytestream ) + { + m_bytestream->play(); + } + } + ~PlayData() { if ( m_bytestream ) @@ -149,7 +161,6 @@ bool AudioPlayer::Private::play( const SoundInfo& si ) data->m_mediaobject->setUrl( url ); m_playing.insert( newid, data ); valid = true; - data->m_mediaobject->play(); kDebug() << "[AudioPlayer::Playinfo::play()] PLAY url" << endl; } } @@ -176,7 +187,6 @@ bool AudioPlayer::Private::play( const SoundInfo& si ) data->m_bytestream->setStreamSeekable( true ); data->m_bytestream->endOfData(); valid = true; - data->m_bytestream->play(); kDebug() << "[AudioPlayer::Playinfo::play()] PLAY data" << endl; } } @@ -189,6 +199,10 @@ bool AudioPlayer::Private::play( const SoundInfo& si ) delete data; data = 0; } + if ( data ) + { + data->play(); + } return valid; } @@ -204,8 +218,18 @@ void AudioPlayer::Private::finished( int id ) if ( it == m_playing.end() ) return; - delete it.value(); - m_playing.erase( it ); + SoundInfo si = it.value()->m_info; + // if the sound must be repeated indefinitely, then start the playback + // again, otherwise destroy the PlayData as it's no more useful + if ( si.repeat ) + { + it.value()->play(); + } + else + { + delete it.value(); + m_playing.erase( it ); + } kDebug() << k_funcinfo << "finished, " << m_playing.count() << endl; } @@ -243,4 +267,9 @@ void AudioPlayer::playSound( const Sound * sound, const LinkSound * linksound ) d->play( si ); } +void AudioPlayer::stopPlaybacks() +{ + d->stopPlayings(); +} + #include "audioplayer.moc" diff --git a/core/audioplayer.h b/core/audioplayer.h index 538d2a5d9..53088f687 100644 --- a/core/audioplayer.h +++ b/core/audioplayer.h @@ -43,6 +43,11 @@ class OKULAR_EXPORT AudioPlayer : public QObject */ void playSound( const Sound * sound, const LinkSound * linksound = 0 ); + /** + * Tell the AudioPlayer to stop all the playbacks. + */ + void stopPlaybacks(); + private: AudioPlayer();