7#include "audioplayer.h"
10#include <KLocalizedString>
14#include <QRandomGenerator>
16#include "config-okular.h"
19#include <phonon/abstractmediastream.h>
20#include <phonon/audiooutput.h>
21#include <phonon/mediaobject.h>
22#include <phonon/path.h>
41class AudioPlayerPrivate
46 ~AudioPlayerPrivate();
49 bool play(
const SoundInfo &si);
57 QUrl m_currentDocument;
66 explicit SoundInfo(
const Sound *s =
nullptr,
const SoundAction *ls =
nullptr)
75 synchronous = ls->synchronous();
92 : m_mediaobject(nullptr)
103 m_mediaobject->play();
108 m_mediaobject->stop();
109 delete m_mediaobject;
114 PlayData(
const PlayData &) =
delete;
115 PlayData &operator=(
const PlayData &) =
delete;
123AudioPlayerPrivate::AudioPlayerPrivate(
AudioPlayer *qq)
129AudioPlayerPrivate::~AudioPlayerPrivate()
134int AudioPlayerPrivate::newId()
const
141 newid = random->bounded(RAND_MAX);
142 it = m_playing.constFind(newid);
143 }
while (it != itEnd);
147bool AudioPlayerPrivate::play(
const SoundInfo &si)
149 qCDebug(OkularCoreDebug);
150 PlayData *data =
new PlayData();
152 data->m_output->setVolume(si.volume);
154 Phonon::createPath(data->m_mediaobject, data->m_output);
158 switch (si.sound->soundType()) {
161 qCDebug(OkularCoreDebug) <<
"External," << url;
166 data->m_mediaobject->setCurrentSource(newurl);
167 m_playing.insert(newid, data);
174 qCDebug(OkularCoreDebug) <<
"Embedded," << filedata.
length();
176 qCDebug(OkularCoreDebug) <<
"Mediaobject:" << data->m_mediaobject;
179 data->m_buffer =
new QBuffer();
180 data->m_buffer->setData(filedata);
182 m_playing.insert(newid, data);
193 qCDebug(OkularCoreDebug) <<
"PLAY";
200void AudioPlayerPrivate::stopPlayings()
202 qDeleteAll(m_playing);
207void AudioPlayerPrivate::finished(
int id)
210 if (it == m_playing.end()) {
214 SoundInfo si = it.value()->m_info;
224 qCDebug(OkularCoreDebug) <<
"finished," << m_playing.count();
227AudioPlayer::AudioPlayer()
229 , d(new AudioPlayerPrivate(this))
233AudioPlayer::~AudioPlayer()
256 qCDebug(OkularCoreDebug);
257 SoundInfo si(sound, linksound);
278void AudioPlayer::resetDocument()
280 d->m_currentDocument = {};
286 d->m_currentDocument = url;
293class AudioPlayerPrivate
300AudioPlayer::AudioPlayer()
301 : d(new AudioPlayerPrivate())
315 Q_EMIT d->document->
warning(
i18n(
"This Okular is built without audio support"), 2000);
320 return State::StoppedState;
327AudioPlayer::~AudioPlayer() noexcept
331void AudioPlayer::resetDocument()
333 d->document =
nullptr;
339 d->document = document;
344#include "moc_audioplayer.cpp"
void playSound(const Sound *sound, const SoundAction *linksound=nullptr)
Enqueue the specified sound for playing, optionally taking more information about the playing from th...
void stopPlaybacks()
Tell the AudioPlayer to stop all the playbacks.
State state() const
Return state of sound (playing/stopped)
static AudioPlayer * instance()
Gets the instance of the audio player.
State
The state of AudioPlayer.
@ StoppedState
The AudioPlayer isn't playing a audio file.
@ PlayingState
The AudioPlayer is playing a audio file.
void warning(const QString &text, int duration)
This signal is emitted to signal a warning.
The Sound action plays a sound on activation.
Contains information about a sound object.
SoundType soundType() const
Returns the type of the sound object.
@ Embedded
Is stored embedded in the document.
@ External
Is stored at external resource (e.g. url)
QString i18n(const char *text, const TYPE &arg...)
KGUIADDONS_EXPORT QColor mix(const QColor &c1, const QColor &c2, qreal bias=0.5)
QAction * repeat(const QObject *recvr, const char *slot, QObject *parent)
bool isEmpty() const const
qsizetype length() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QRandomGenerator * global()
bool isEmpty() const const