Qt
6.x
The Qt SDK
Loading...
Searching...
No Matches
qquick3dambientsound.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
3
#include "
qquick3dambientsound_p.h
"
4
#include "
qquick3daudioengine_p.h
"
5
#include "
qambientsound.h
"
6
#include <QAudioFormat>
7
#include <
qdir.h
>
8
#include <QQmlContext>
9
#include <QQmlFile>
10
11
QT_BEGIN_NAMESPACE
12
26
QQuick3DAmbientSound::QQuick3DAmbientSound
()
27
{
28
m_sound =
new
QAmbientSound
(
QQuick3DAudioEngine::getEngine
());
29
30
connect
(m_sound, &
QAmbientSound::sourceChanged
,
this
, &
QQuick3DAmbientSound::sourceChanged
);
31
connect
(m_sound, &
QAmbientSound::volumeChanged
,
this
, &
QQuick3DAmbientSound::volumeChanged
);
32
connect
(m_sound, &
QAmbientSound::loopsChanged
,
this
, &
QQuick3DAmbientSound::loopsChanged
);
33
connect
(m_sound, &
QAmbientSound::autoPlayChanged
,
this
, &
QQuick3DAmbientSound::autoPlayChanged
);
34
}
35
36
QQuick3DAmbientSound::~QQuick3DAmbientSound
()
37
{
38
delete
m_sound;
39
}
40
46
QUrl
QQuick3DAmbientSound::source
()
const
47
{
48
return
m_sound->
source
();
49
}
50
51
void
QQuick3DAmbientSound::setSource
(
QUrl
source
)
52
{
53
const
QQmlContext
*
context
=
qmlContext
(
this
);
54
QUrl
url
;
55
if
(
context
) {
56
url
=
context
->resolvedUrl(
source
);
57
}
else
{
58
url
=
QUrl::fromLocalFile
(
QDir::currentPath
() + u
"/"
);
59
url
=
url
.
resolved
(
source
);
60
}
61
m_sound->
setSource
(
url
);
62
}
63
69
void
QQuick3DAmbientSound::setVolume
(
float
volume)
70
{
71
m_sound->
setVolume
(
volume
);
72
}
73
74
float
QQuick3DAmbientSound::volume
()
const
75
{
76
return
m_sound->
volume
();
77
}
78
87
int
QQuick3DAmbientSound::loops
()
const
88
{
89
return
m_sound->
loops
();
90
}
91
92
void
QQuick3DAmbientSound::setLoops
(
int
loops)
93
{
94
m_sound->
setLoops
(
loops
);
95
}
96
105
bool
QQuick3DAmbientSound::autoPlay
()
const
106
{
107
return
m_sound->
autoPlay
();
108
}
109
110
void
QQuick3DAmbientSound::setAutoPlay
(
bool
autoPlay)
111
{
112
m_sound->
setAutoPlay
(
autoPlay
);
113
}
114
120
void
QQuick3DAmbientSound::play
()
121
{
122
m_sound->
play
();
123
}
124
130
void
QQuick3DAmbientSound::pause
()
131
{
132
m_sound->
pause
();
133
}
134
141
void
QQuick3DAmbientSound::stop
()
142
{
143
m_sound->
stop
();
144
}
145
146
QT_END_NAMESPACE
QAmbientSound
\inmodule QtSpatialAudio
Definition
qambientsound.h:17
QAmbientSound::setAutoPlay
void setAutoPlay(bool autoPlay)
Definition
qambientsound.cpp:126
QAmbientSound::volumeChanged
void volumeChanged()
QAmbientSound::pause
void pause()
Pauses sound playback.
Definition
qambientsound.cpp:144
QAmbientSound::setLoops
void setLoops(int loops)
Definition
qambientsound.cpp:106
QAmbientSound::play
void play()
Starts playing back the sound.
Definition
qambientsound.cpp:136
QAmbientSound::loopsChanged
void loopsChanged()
QAmbientSound::loops
int loops
Determines how many times the sound is played before the player stops.
Definition
qambientsound.h:21
QAmbientSound::volume
float volume
Defines the volume of the sound.
Definition
qambientsound.h:20
QAmbientSound::autoPlay
bool autoPlay
Determines whether the sound should automatically start playing when a source gets specified.
Definition
qambientsound.h:22
QAmbientSound::sourceChanged
void sourceChanged()
QAmbientSound::autoPlayChanged
void autoPlayChanged()
QAmbientSound::setSource
void setSource(const QUrl &url)
Definition
qambientsound.cpp:65
QAmbientSound::source
QUrl source
The source file for the sound to be played.
Definition
qambientsound.h:19
QAmbientSound::stop
void stop()
Stops sound playback and resets the current position and current loop count to 0.
Definition
qambientsound.cpp:153
QAmbientSound::setVolume
void setVolume(float volume)
Definition
qambientsound.cpp:49
QDir::currentPath
static QString currentPath()
Returns the absolute path of the application's current directory.
Definition
qdir.cpp:2051
QObject::connect
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition
qobject.cpp:2823
QQmlContext
The QQmlContext class defines a context within a QML engine.
Definition
qqmlcontext.h:25
QQuick3DAmbientSound::autoPlayChanged
void autoPlayChanged()
QQuick3DAmbientSound::loops
int loops
Definition
qquick3dambientsound_p.h:30
QQuick3DAmbientSound::setAutoPlay
void setAutoPlay(bool autoPlay)
Definition
qquick3dambientsound.cpp:110
QQuick3DAmbientSound::setSource
void setSource(QUrl source)
Definition
qquick3dambientsound.cpp:51
QQuick3DAmbientSound::setLoops
void setLoops(int loops)
Definition
qquick3dambientsound.cpp:92
QQuick3DAmbientSound::play
void play()
\qmlmethod AmbientSound::play()
Definition
qquick3dambientsound.cpp:120
QQuick3DAmbientSound::pause
void pause()
\qmlmethod AmbientSound::pause()
Definition
qquick3dambientsound.cpp:130
QQuick3DAmbientSound::sourceChanged
void sourceChanged()
QQuick3DAmbientSound::loopsChanged
void loopsChanged()
QQuick3DAmbientSound::stop
void stop()
\qmlmethod AmbientSound::stop()
Definition
qquick3dambientsound.cpp:141
QQuick3DAmbientSound::autoPlay
bool autoPlay
Definition
qquick3dambientsound_p.h:31
QQuick3DAmbientSound::QQuick3DAmbientSound
QQuick3DAmbientSound()
\qmltype AmbientSound \inqmlmodule QtQuick3D.SpatialAudio
Definition
qquick3dambientsound.cpp:26
QQuick3DAmbientSound::setVolume
void setVolume(float volume)
\qmlproperty float AmbientSound::volume
Definition
qquick3dambientsound.cpp:69
QQuick3DAmbientSound::source
QUrl source
Definition
qquick3dambientsound_p.h:28
QQuick3DAmbientSound::~QQuick3DAmbientSound
~QQuick3DAmbientSound()
Definition
qquick3dambientsound.cpp:36
QQuick3DAmbientSound::volume
float volume
Definition
qquick3dambientsound_p.h:29
QQuick3DAmbientSound::volumeChanged
void volumeChanged()
QQuick3DAudioEngine::getEngine
static QAudioEngine * getEngine()
Definition
qquick3daudioengine.cpp:117
QUrl
\inmodule QtCore
Definition
qurl.h:94
QUrl::fromLocalFile
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition
qurl.cpp:3354
QUrl::resolved
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition
qurl.cpp:2722
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qstandardpaths_haiku.cpp:21
QT_END_NAMESPACE
Definition
qsharedpointer.cpp:1545
qambientsound.h
context
static void * context
Definition
qandroidaudiosource.cpp:42
qdir.h
source
GLsizei GLsizei GLchar * source
Definition
qopengles2ext.h:952
qmlContext
QQmlContext * qmlContext(const QObject *obj)
Definition
qqml.cpp:71
qquick3dambientsound_p.h
qquick3daudioengine_p.h
url
QUrl url("example.com")
[constructor-url-reference]
Definition
src_corelib_io_qurl.cpp:19
qtmultimedia
src
spatialaudioquick3d
qquick3dambientsound.cpp
Generated by
1.9.7