summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qsound.cpp15
-rw-r--r--src/multimedia/audio/qsound.h2
-rw-r--r--src/multimedia/audio/qsoundeffect_qaudio_p.cpp8
-rw-r--r--src/multimedia/audio/qsoundeffect_qaudio_p.h8
4 files changed, 21 insertions, 12 deletions
diff --git a/src/multimedia/audio/qsound.cpp b/src/multimedia/audio/qsound.cpp
index b6cf49671..cbd336457 100644
--- a/src/multimedia/audio/qsound.cpp
+++ b/src/multimedia/audio/qsound.cpp
@@ -60,6 +60,9 @@
\snippet multimedia-snippets/qsound.cpp 1
+ In both cases, the file may either be a local file or in a
+ \l{The Qt Resource System}{resource}.
+
Once created a QSound object can be queried for its fileName() and
total number of loops() (i.e. the number of times the sound will
play). The number of repetitions can be altered using the
@@ -88,9 +91,11 @@
/*!
Plays the sound stored in the file specified by the given \a filename.
+ The file can either be a local file or in a \l{The Qt Resource System}{resource}.
+
\sa stop(), loopsRemaining(), isFinished()
*/
-void QSound::play(const QString& filename)
+void QSound::play(const QString &filename)
{
// Object destruction is generally handled via deleteOnComplete
// Unexpected cases will be handled via parenting of QSound objects to qApp
@@ -104,13 +109,17 @@ void QSound::play(const QString& filename)
Constructs a QSound object from the file specified by the given \a
filename and with the given \a parent.
+ The file can either be a local file or in a \l{The Qt Resource System}{resource}.
+
\sa play()
*/
-QSound::QSound(const QString& filename, QObject* parent)
+QSound::QSound(const QString &filename, QObject *parent)
: QObject(parent)
{
m_soundEffect = new QSoundEffect(this);
- m_soundEffect->setSource(QUrl::fromLocalFile(filename));
+ const bool isQrc = filename.startsWith(QLatin1String("qrc:"), Qt::CaseInsensitive);
+ const QUrl url = isQrc ? QUrl(filename) : QUrl::fromLocalFile(filename);
+ m_soundEffect->setSource(url);
}
/*!
diff --git a/src/multimedia/audio/qsound.h b/src/multimedia/audio/qsound.h
index 57a254050..972847c37 100644
--- a/src/multimedia/audio/qsound.h
+++ b/src/multimedia/audio/qsound.h
@@ -56,7 +56,7 @@ public:
Infinite = -1
};
- static void play(const QString& filename);
+ static void play(const QString &filename);
explicit QSound(const QString &filename, QObject *parent = nullptr);
~QSound();
diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
index 73f1d5cfd..388f84d91 100644
--- a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
+++ b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QSampleCache, sampleCache)
-QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent):
+QSoundEffectPrivate::QSoundEffectPrivate(QObject *parent):
QObject(parent),
d(new PrivateSoundSource(this))
{
@@ -302,7 +302,7 @@ void QSoundEffectPrivate::setCategory(const QString &category)
}
}
-PrivateSoundSource::PrivateSoundSource(QSoundEffectPrivate* s):
+PrivateSoundSource::PrivateSoundSource(QSoundEffectPrivate *s):
QIODevice(s)
{
soundeffect = s;
@@ -354,7 +354,7 @@ void PrivateSoundSource::stateChanged(QAudio::State state)
emit soundeffect->stop();
}
-qint64 PrivateSoundSource::readData( char* data, qint64 len)
+qint64 PrivateSoundSource::readData(char *data, qint64 len)
{
if ((m_runningCount > 0 || m_runningCount == QSoundEffect::Infinite) && m_playing) {
@@ -428,7 +428,7 @@ qint64 PrivateSoundSource::readData( char* data, qint64 len)
return 0;
}
-qint64 PrivateSoundSource::writeData(const char* data, qint64 len)
+qint64 PrivateSoundSource::writeData(const char *data, qint64 len)
{
Q_UNUSED(data)
Q_UNUSED(len)
diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.h b/src/multimedia/audio/qsoundeffect_qaudio_p.h
index db48e7ca6..c02a85969 100644
--- a/src/multimedia/audio/qsoundeffect_qaudio_p.h
+++ b/src/multimedia/audio/qsoundeffect_qaudio_p.h
@@ -66,11 +66,11 @@ class PrivateSoundSource : public QIODevice
friend class QSoundEffectPrivate;
Q_OBJECT
public:
- PrivateSoundSource(QSoundEffectPrivate* s);
+ PrivateSoundSource(QSoundEffectPrivate *s);
~PrivateSoundSource() {}
- qint64 readData( char* data, qint64 len) override;
- qint64 writeData(const char* data, qint64 len) override;
+ qint64 readData(char *data, qint64 len) override;
+ qint64 writeData(const char *data, qint64 len) override;
private Q_SLOTS:
void sampleReady();
@@ -101,7 +101,7 @@ class QSoundEffectPrivate : public QObject
Q_OBJECT
public:
- explicit QSoundEffectPrivate(QObject* parent);
+ explicit QSoundEffectPrivate(QObject *parent);
~QSoundEffectPrivate();
static QStringList supportedMimeTypes();