The QSound class provides access to the platform audio facilities. 更多...
| 頭: | #include <QSound> |
| 繼承: | QObject |
| QSound (const QString & filename , QObject * parent = 0) | |
| ~QSound () | |
| QString | fileName () const |
| bool | isFinished () const |
| int | loops () const |
| int | loopsRemaining () const |
| void | setLoops (int number ) |
| void | play () |
| void | stop () |
| bool | isAvailable () |
| void | play (const QString & filename ) |
The QSound class provides access to the platform audio facilities.
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 () function, but it may also play more immediately (depending on the underlying platform audio facilities). Use the static isAvailable () function to determine whether sound facilities exist on the platform. Which facilities that are actually used varies:
| 平颱 | Audio Facility |
|---|---|
| 微軟 Windows | The underlying multimedia system is used; only WAVE format sound files are supported. |
| X11 | The Network Audio System is used if available, otherwise all operations work silently. NAS supports WAVE and AU files. |
| Mac OS X | NSSound is used. All formats that NSSound supports, including QuickTime formats, are supported by Qt for Mac OS X. |
| Qt for Embedded Linux |
A built-in mixing sound server is used, accessing
/dev/dsp
directly. Only the WAVE format is supported.
|
| Symbian | CMdaAudioPlayerUtility is used. All formats that Symbian OS or devices support are supported also by Qt. |
注意, QSound 不支持 resources . This might be fixed in a future Qt version.
構造 QSound object from the file specified by the given filename 和采用給定 parent .
This may use more memory than the static play () 函數,但也可能更直接發揮作用 (從屬底層平颱音頻設施)。
另請參閱 play ().
Destroys this sound object. If the sound is not finished playing, the stop () function is called before the sound object is destructed.
另請參閱 stop () 和 isFinished ().
返迴的文件名關聯此 QSound 對象。
另請參閱 QSound ().
[static]
bool
QSound::
isAvailable
()
Returns true if sound facilities exist on the platform; otherwise returns false.
If no sound is available, all QSound operations work silently and quickly. An application may choose either to notify the user if sound is crucial to the application or to operate silently without bothering the user.
Note: On Windows this always returns true because some sound card drivers do not implement a way to find out whether it is available or not.
Returns true if the sound has finished playing; otherwise returns false.
警告: On Windows this function always returns true for unlooped sounds.
Returns the number of times the sound will play.
另請參閱 loopsRemaining () 和 setLoops ().
Returns the remaining number of times the sound will loop (this value decreases each time the sound is played).
另請參閱 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 ().
把聲音設為重復給定 number 的次數,當播放它時。
Note that passing the value -1 will cause the sound to loop indefinitely.
另請參閱 loops ().
[slot]
void
QSound::
stop
()
停止播放聲音。
Note that on Windows the current loop will finish if a sound is played in a loop.
另請參閱 play ().