QSound¶
Synopsis¶
Functions¶
def
fileName
()def
isFinished
()def
loops
()def
loopsRemaining
()def
setLoops
(arg__1)
Slots¶
Static functions¶
def
play
(filename)
Detailed Description¶
Qt provides the most commonly required audio operation in GUI applications: asynchronously playing a sound file. This is most easily accomplished using the static
play()
function:QSound::play("mysounds/bells.wav");Alternatively, create a
QSound
object from the sound file first and then call theplay()
slot:QSound bells("mysounds/bells.wav"); bells.play();In both cases, the file may either be a local file or in a resource .
Once created a
QSound
object can be queried for itsfileName()
and total number ofloops()
(i.e. the number of times the sound will play). The number of repetitions can be altered using thesetLoops()
function. While playing the sound, theloopsRemaining()
function returns the remaining number of repetitions. Use theisFinished()
function to determine whether the sound has finished playing.Sounds played using a
QSound
object may use more memory than the staticplay()
function, but it may also play more immediately (depending on the underlying platform audio facilities).If you require finer control over playing sounds, consider the
QSoundEffect
orQAudioOutput
classes.See also
- class PySide2.QtMultimedia.QSound(filename[, parent=None])¶
- param parent:
- param filename:
str
Constructs a
QSound
object from the file specified by the givenfilename
and with the givenparent
.The file can either be a local file or in a resource .
See also
- PySide2.QtMultimedia.QSound.Loop¶
Constant
Description
QSound.Infinite
Can be used as a parameter to
setLoops()
to loop infinitely.
- PySide2.QtMultimedia.QSound.fileName()¶
- Return type:
str
Returns the filename associated with this
QSound
object.See also
QSound()
- PySide2.QtMultimedia.QSound.isFinished()¶
- Return type:
bool
Returns true if the sound has finished playing; otherwise returns false.
- PySide2.QtMultimedia.QSound.loops()¶
- Return type:
int
Returns the number of times the sound will play. Return value of
QSound::Infinite
indicates infinite number of loopsSee also
- PySide2.QtMultimedia.QSound.loopsRemaining()¶
- Return type:
int
Returns the remaining number of times the sound will loop (for all positive values this value decreases each time the sound is played). Return value of
QSound::Infinite
indicates infinite number of loopsSee also
- PySide2.QtMultimedia.QSound.play()¶
This is an overloaded function.
Starts playing the sound specified by this
QSound
object.The function returns immediately. Depending on the platform audio facilities, other sounds may stop or be mixed with the new sound. The sound can be played again at any time, possibly mixing or replacing previous plays of the sound.
See also
- static PySide2.QtMultimedia.QSound.play(filename)
- Parameters:
filename – str
Plays the sound stored in the file specified by the given
filename
.The file can either be a local file or in a resource .
See also
- PySide2.QtMultimedia.QSound.setLoops(arg__1)¶
- Parameters:
arg__1 – int
Sets the sound to repeat the given
number
of times when it is played.Note that passing the value
QSound::Infinite
will cause the sound to loop indefinitely.See also
© 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.