summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2018-03-24 13:21:18 +0100
committerAndré Hartmann <aha_1980@gmx.de>2018-04-25 08:10:13 +0000
commitfa8f2114bdb98160921711cd272ab1c9503ab9c3 (patch)
treecabc28a34c7a15fcfb4a0de50a2d06b680800f06 /src/multimedia
parent08dd127bd7c3900bdb9c73d646a12aae2383a9fb (diff)
QSound: Allow to play files with qrc schema
It was possible to play resource files only by prefix ":/". Added support of qrc schema in filenames. Change-Id: I9e538422828ad2107ab5567d172dca8728cbc64d Reviewed-by: VaL Doroshchuk <valentyn.doroshchuk@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/audio/qsound.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/multimedia/audio/qsound.cpp b/src/multimedia/audio/qsound.cpp
index b6cf49671..7ad30608d 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,6 +91,8 @@
/*!
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)
@@ -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)
: 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);
}
/*!