QSound 類

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 = Q_NULLPTR)
~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 )

額外繼承成員

詳細描述

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();
					

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 .

成員類型文檔編製

enum QSound:: Loop

常量 描述
QSound::Infinite -1 可以作為參數用於 setLoops () 以無限循環。

成員函數文檔編製

QSound:: QSound (const QString & filename , QObject * parent = Q_NULLPTR)

構造 QSound object from the file specified by the given filename 和采用給定 parent .

另請參閱 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 ().

QString QSound:: fileName () const

返迴的文件名關聯此 QSound 對象。

另請參閱 QSound ().

bool QSound:: isFinished () const

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

int QSound:: loops () const

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

另請參閱 loopsRemaining () 和 setLoops ().

int QSound:: loopsRemaining () const

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 .

另請參閱 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 ().

void QSound:: setLoops ( int number )

把聲音設為重復給定 number 的次數,當播放它時。

注意,傳遞值 QSound::Infinite 將導緻聲音無限循環。

另請參閱 loops ().

[slot] void QSound:: stop ()

停止播放聲音。

另請參閱 play ().