Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
5
6#include <QtMultimediaQuick/private/qqmlcontext_source_resolver_p.h>
7#include <QtQuick3DSpatialAudio/private/qquick3daudioengine_p.h>
8#include <QtSpatialAudio/qambientsound.h>
9#include <QtSpatialAudio/private/qambientsound_p.h>
10
12
13/*!
14 \qmltype AmbientSound
15 \inqmlmodule QtQuick3D.SpatialAudio
16 \ingroup quick3d_spatialaudio
17 \ingroup multimedia_audio_qml
18
19 \brief A stereo overlay sound.
20
21 A AmbientSound represents a position and orientation independent sound.
22 It's commonly used for background sounds (e.g. music) that is supposed to be independent
23 of the listeners position and orientation.
24 */
25
26QQuick3DAmbientSound::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 auto *soundPrivate = QAmbientSoundPrivate::get(m_sound);
36 soundPrivate->m_sourceResolver =
37 std::make_unique<QMultimediaPrivate::QQmlContextSourceResolver>(this);
38}
39
41{
42 delete m_sound;
43}
44
45/*!
46 \qmlproperty url AmbientSound::source
47
48 The source file for the sound to be played.
49 */
51{
52 return m_sound->source();
53}
54
56{
57 m_sound->setSource(source);
58}
59
60/*!
61 \qmlproperty real AmbientSound::volume
62
63 Defines an overall volume for this sound source.
64 */
66{
67 m_sound->setVolume(volume);
68}
69
71{
72 return m_sound->volume();
73}
74
75/*!
76 \qmlproperty int AmbientSound::loops
77
78 Determines how often the sound is played before the player stops.
79 Set to QAmbienSound::Infinite to loop the current sound forever.
80
81 The default value is \c 1.
82 */
83int QQuick3DAmbientSound::loops() const
84{
85 return m_sound->loops();
86}
87
89{
90 m_sound->setLoops(loops);
91}
92
93/*!
94 \qmlproperty bool AmbientSound::autoPlay
95
96 Determines whether the sound should automatically start playing when a source
97 gets specified.
98
99 The default value is \c true.
100 */
102{
103 return m_sound->autoPlay();
104}
105
107{
108 m_sound->setAutoPlay(autoPlay);
109}
110
111/*!
112 \qmlmethod void AmbientSound::play()
113
114 Starts playing back the sound. Does nothing if the sound is already playing.
115 */
117{
118 m_sound->play();
119}
120
121/*!
122 \qmlmethod void AmbientSound::pause()
123
124 Pauses sound playback at the current position. Calling play() will continue playback.
125 */
127{
128 m_sound->pause();
129}
130
131/*!
132 \qmlmethod void AmbientSound::stop()
133
134 Stops sound playback and resets the current position and loop count to 0. Calling play() will
135 begin playback at the beginning of the sound file.
136 */
138{
139 m_sound->stop();
140}
141
142QT_END_NAMESPACE
void setAutoPlay(bool autoPlay)
void pause()
\qmlmethod void AmbientSound::pause()
void stop()
\qmlmethod void AmbientSound::stop()
bool autoPlay() const
\qmlproperty bool AmbientSound::autoPlay
QUrl source() const
\qmlproperty url AmbientSound::source
void setVolume(float volume)
\qmlproperty real AmbientSound::volume
Combined button and popup list for selecting options.