QSoundEffect¶
The QSoundEffect
class provides a way to play low latency sound effects. More…
Synopsis¶
Functions¶
def
audioDevice
()def
isLoaded
()def
isMuted
()def
isPlaying
()def
loopCount
()def
loopsRemaining
()def
setAudioDevice
(device)def
setLoopCount
(loopCount)def
setMuted
(muted)def
setSource
(url)def
setVolume
(volume)def
source
()def
status
()def
volume
()
Slots¶
Signals¶
def
audioDeviceChanged
()def
loadedChanged
()def
loopCountChanged
()def
loopsRemainingChanged
()def
mutedChanged
()def
playingChanged
()def
sourceChanged
()def
statusChanged
()def
volumeChanged
()
Static functions¶
def
supportedMimeTypes
()
Detailed Description¶
This class allows you to play uncompressed audio files (typically WAV files) in a generally lower latency way, and is suitable for “feedback” type sounds in response to user actions (e.g. virtual keyboard sounds, positive or negative feedback for popup dialogs, or game sounds). If low latency is not important, consider using the QMediaPlayer
class instead, since it supports a wider variety of media formats and is less resource intensive.
This example shows how a looping, somewhat quiet sound effect can be played:
effect = QSoundEffect() effect.setSource(QUrl.fromLocalFile("engine.wav")) effect.setLoopCount(QSoundEffect.Infinite) effect.setVolume(0.25f) effect.play()
Typically the sound effect should be reused, which allows all the parsing and preparation to be done ahead of time, and only triggered when necessary. This assists with lower latency audio playback.
MyGame() self.m_explosion = self m_explosion.setSource(QUrl.fromLocalFile("explosion.wav")) m_explosion.setVolume(0.25f) # Set up click handling etc. connect(clickSource, QPushButton.clicked, m_explosion, QSoundEffect.play) # private m_explosion = QSoundEffect()
Since QSoundEffect
requires slightly more resources to achieve lower latency playback, the platform may limit the number of simultaneously playing sound effects.
- class PySide6.QtMultimedia.QSoundEffect([parent=None])¶
PySide6.QtMultimedia.QSoundEffect(audioDevice[, parent=None])
- Parameters
parent –
PySide6.QtCore.QObject
audioDevice –
PySide6.QtMultimedia.QAudioDevice
Creates a QSoundEffect
with the given parent
.
Creates a QSoundEffect
with the given audioDevice
and parent
.
- PySide6.QtMultimedia.QSoundEffect.Loop¶
Constant
Description
QSoundEffect.Infinite
Used as a parameter to
setLoopCount()
for infinite looping
- PySide6.QtMultimedia.QSoundEffect.Status¶
Constant
Description
QSoundEffect.Null
No source has been set or the source is null.
QSoundEffect.Loading
The SoundEffect is trying to load the source.
QSoundEffect.Ready
The source is loaded and ready for play.
QSoundEffect.Error
An error occurred during operation, such as failure of loading the source.
- PySide6.QtMultimedia.QSoundEffect.audioDevice()¶
- Return type
- PySide6.QtMultimedia.QSoundEffect.audioDeviceChanged()¶
- PySide6.QtMultimedia.QSoundEffect.isLoaded()¶
- Return type
bool
Returns whether the sound effect has finished loading the source()
.
- PySide6.QtMultimedia.QSoundEffect.isMuted()¶
- Return type
bool
This property provides a way to control muting. A value of true
will mute this effect.
- PySide6.QtMultimedia.QSoundEffect.isPlaying()¶
- Return type
bool
This property indicates whether the sound effect is playing or not.
- PySide6.QtMultimedia.QSoundEffect.loadedChanged()¶
- PySide6.QtMultimedia.QSoundEffect.loopCount()¶
- Return type
int
This property holds the number of times the sound is played. A value of 0 or 1 means the sound will be played only once; set to SoundEffect .Infinite to enable infinite looping.
The value can be changed while the sound effect is playing, in which case it will update the remaining loops to the new value.
- PySide6.QtMultimedia.QSoundEffect.loopCountChanged()¶
- PySide6.QtMultimedia.QSoundEffect.loopsRemaining()¶
- Return type
int
This property contains the number of loops remaining before the sound effect stops by itself, or Infinite
if that’s what has been set in loops
.
- PySide6.QtMultimedia.QSoundEffect.loopsRemainingChanged()¶
- PySide6.QtMultimedia.QSoundEffect.mutedChanged()¶
- PySide6.QtMultimedia.QSoundEffect.play()¶
Start playback of the sound effect, looping the effect for the number of times as specified in the loops property.
- PySide6.QtMultimedia.QSoundEffect.playingChanged()¶
- PySide6.QtMultimedia.QSoundEffect.setAudioDevice(device)¶
- Parameters
device –
PySide6.QtMultimedia.QAudioDevice
- PySide6.QtMultimedia.QSoundEffect.setLoopCount(loopCount)¶
- Parameters
loopCount – int
This property holds the number of times the sound is played. A value of 0 or 1 means the sound will be played only once; set to SoundEffect .Infinite to enable infinite looping.
The value can be changed while the sound effect is playing, in which case it will update the remaining loops to the new value.
- PySide6.QtMultimedia.QSoundEffect.setMuted(muted)¶
- Parameters
muted – bool
This property provides a way to control muting. A value of true
will mute this effect.
- PySide6.QtMultimedia.QSoundEffect.setSource(url)¶
- Parameters
url –
PySide6.QtCore.QUrl
This property holds the url for the sound to play. For the SoundEffect to attempt to load the source, the URL must exist and the application must have read permission in the specified directory.
- PySide6.QtMultimedia.QSoundEffect.setVolume(volume)¶
- Parameters
volume – float
This property holds the volume of the sound effect playback, from 0.0 (silence) to 1.0 (full volume).
- PySide6.QtMultimedia.QSoundEffect.source()¶
- Return type
This property holds the url for the sound to play. For the SoundEffect to attempt to load the source, the URL must exist and the application must have read permission in the specified directory.
- PySide6.QtMultimedia.QSoundEffect.sourceChanged()¶
This property indicates the current status of the sound effect from the Status
enumeration.
- PySide6.QtMultimedia.QSoundEffect.statusChanged()¶
- PySide6.QtMultimedia.QSoundEffect.stop()¶
Stop current playback.
- static PySide6.QtMultimedia.QSoundEffect.supportedMimeTypes()¶
- Return type
list of strings
Returns a list of the supported mime types for this platform.
- PySide6.QtMultimedia.QSoundEffect.volume()¶
- Return type
float
This property holds the volume of the sound effect playback, from 0.0 (silence) to 1.0 (full volume).
- PySide6.QtMultimedia.QSoundEffect.volumeChanged()¶
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.