QSound 类

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:: QSound (const QString & filename , QObject * parent = 0)

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

This may use more memory than the static play () 函数,但也可能更直接发挥作用 (从属底层平台音频设施)。

另请参阅 play ().

QSound:: ~QSound ()

Destroys this sound object. If the sound is not finished playing, the stop () function is called before the sound object is destructed.

另请参阅 stop () 和 isFinished ().

QString QSound:: fileName () const

返回的文件名关联此 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.

bool QSound:: isFinished () const

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

警告: On Windows this function always returns true for unlooped sounds.

int QSound:: loops () const

Returns the number of times the sound will play.

另请参阅 loopsRemaining () 和 setLoops ().

int QSound:: loopsRemaining () const

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

void QSound:: setLoops ( int number )

把声音设为重复给定 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 ().