内容表

上一话题

QRadioTunerControl

下一话题

QSoundEffect

QSound

QSound class provides a method to play .wav sound files. 更多

Inheritance diagram of PySide2.QtMultimedia.QSound

概要

函数

静态函数

详细描述

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() 函数:

QSound::play("mysounds/bells.wav");
											

Alternatively, create a QSound object from the sound file first and then call the play() 槽:

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 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 setLoops() function. While playing the sound, the loopsRemaining() function returns the remaining number of repetitions. Use the isFinished() function to determine whether the sound has finished playing.

Sounds played using a QSound object may use more memory than the static play() 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 or QAudioOutput 类。

另请参阅

QSoundEffect

class QSound ( filename [ , parent=None ] )
param parent

QObject

param filename

unicode

构造 QSound object from the file specified by the given filename and with the given parent .

The file can either be a local file or in a resource .

另请参阅

play()

PySide2.QtMultimedia.QSound. Loop

常量

描述

QSound.Infinite

Can be used as a parameter to setLoops() to loop infinitely.

PySide2.QtMultimedia.QSound. fileName ( )
返回类型

unicode

Returns the filename associated with this QSound 对象。

另请参阅

QSound()

PySide2.QtMultimedia.QSound. isFinished ( )
返回类型

bool

Returns true if the sound has finished playing; otherwise returns false.

PySide2.QtMultimedia.QSound. loops ( )
返回类型

int

Returns the number of times the sound will play. Return value of QSound::Infinite indicates infinite number of loops

PySide2.QtMultimedia.QSound. loopsRemaining ( )
返回类型

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 loops

PySide2.QtMultimedia.QSound. play ( )

这是重载函数。

Starts playing the sound specified by this QSound 对象。

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.

另请参阅

fileName()

static PySide2.QtMultimedia.QSound. play ( filename )
参数

filename – unicode

Plays the sound stored in the file specified by the given filename .

The file can either be a local file or in a resource .

PySide2.QtMultimedia.QSound. setLoops ( arg__1 )
参数

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.

另请参阅

loops()

PySide2.QtMultimedia.QSound. stop ( )

Stops the sound playing.

另请参阅

play()