The QSound class provides a method to play .wav sound files. 更多...
| 頭: | #include <QSound> |
| qmake: | QT += multimedia |
| 繼承: | QObject |
| enum | Loop { Infinite } |
| QSound (const QString & filename , QObject * parent = nullptr) | |
| virtual | ~QSound () |
| QString | fileName () const |
| bool | isFinished () const |
| int | loops () const |
| int | loopsRemaining () const |
| void | setLoops (int number ) |
| void | play () |
| void | stop () |
| void | play (const QString & filename ) |
| const QMetaObject | staticMetaObject |
The QSound class provides a method to play .wav sound files.
Qt 提供在 GUI 應用程序中,最常要求的音頻操作:異步播放聲音文件。這最易施行,使用靜態 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();
在這 2 種情況下,文件要麼可以是本地文件,要麼可以是在 resource .
Once created a QSound object can be queried for its fileName () 和總數對於 loops () (即:聲音將播放的次數)。重復次數的變更可以使用 setLoops () 函數。當播放聲音時, loopsRemaining () 函數返迴剩餘的重復次數。使用 isFinished () 函數,確定聲音是否已播放完成。
Sounds played using a QSound object may use more memory than the static play () 函數,但也可能更直接發揮作用 (從屬底層平颱音頻設施)。
若要求更精細控製聲音播放,考慮 QSoundEffect or QAudioOutput 類。
另請參閱 QSoundEffect .
| 常量 | 值 | 描述 |
|---|---|---|
QSound::Infinite
|
-1
|
可以作為參數用於 setLoops () 以無限循環。 |
構造 QSound object from the file specified by the given filename 和采用給定 parent .
文件要麼可以是本地文件,要麼可以是在 resource .
另請參閱 play ().
[虛擬]
QSound::
~QSound
()
Destroys this sound object. If the sound is not finished playing, the stop () function is called before the sound object is destroyed.
另請參閱 stop () 和 isFinished ().
返迴的文件名關聯此 QSound 對象。
另請參閱 QSound ().
Returns true if the sound has finished playing; otherwise returns false.
Returns the number of times the sound will play. Return value of
QSound::Infinite
indicates infinite number of loops
另請參閱 loopsRemaining () 和 setLoops ().
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
另請參閱 loops () 和 isFinished ().
[static]
void
QSound::
play
(const
QString
&
filename
)
播放聲音存儲在的文件指定通過給定 filename .
文件要麼可以是本地文件,要麼可以是在 resource .
另請參閱 stop (), loopsRemaining (),和 isFinished ().
[slot]
void
QSound::
play
()
這是重載函數。
開始播放聲音指定通過此 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 ().
把聲音設為重復給定 number 的次數,當播放它時。
注意,傳遞值
QSound::Infinite
將導緻聲音無限循環。
另請參閱 loops ().
[slot]
void
QSound::
stop
()
停止播放聲音。
另請參閱 play ().