PySide.QtGui.QSound class provides access to the platform audio facilities.
Qt provides the most commonly required audio operation in GUI applications: asynchronously playing a sound file. This is most easily accomplished using the static PySide.QtGui.QSound.play() 函数:
QSound.play("mysounds/bells.wav")
Alternatively, create a PySide.QtGui.QSound object from the sound file first and then call the PySide.QtGui.QSound.play() 槽:
bells = QSound("mysounds/bells.wav")
bells.play()
Once created a PySide.QtGui.QSound object can be queried for its PySide.QtGui.QSound.fileName() and total number of PySide.QtGui.QSound.loops() (i.e. the number of times the sound will play). The number of repetitions can be altered using the PySide.QtGui.QSound.setLoops() function. While playing the sound, the PySide.QtGui.QSound.loopsRemaining() function returns the remaining number of repetitions. Use the PySide.QtGui.QSound.isFinished() function to determine whether the sound has finished playing.
Sounds played using a PySide.QtGui.QSound object may use more memory than the static PySide.QtGui.QSound.play() function, but it may also play more immediately (depending on the underlying platform audio facilities). Use the static PySide.QtGui.QSound.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. |
注意: PySide.QtGui.QSound 不支持 resources . This might be fixed in a future Qt version.
| 参数: |
|
|---|
构造 PySide.QtGui.QSound object from the file specified by the given filename and with the given parent .
This may use more memory than the static PySide.QtGui.QSound.play() function, but it may also play more immediately (depending on the underlying platform audio facilities).
| 返回类型: | unicode |
|---|
Returns the filename associated with this PySide.QtGui.QSound 对象。
另请参阅
PySide.QtGui.QSound.QSound()
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if sound facilities exist on the platform; otherwise returns false.
If no sound is available, all PySide.QtGui.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.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the sound has finished playing; otherwise returns false.
警告
On Windows this function always returns true for unlooped sounds.
| 返回类型: | PySide.QtCore.int |
|---|
Returns the number of times the sound will play.
| 返回类型: | PySide.QtCore.int |
|---|
Returns the remaining number of times the sound will loop (this value decreases each time the sound is played).
| 参数: | filename – unicode |
|---|
Plays the sound stored in the file specified by the given filename .
这是重载函数。
Starts playing the sound specified by this PySide.QtGui.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.
| 参数: | arg__1 – PySide.QtCore.int |
|---|
Sets the sound to repeat the given number of times when it is played.
Note that passing the value -1 will cause the sound to loop indefinitely.
Stops the sound playing.
Note that on Windows the current loop will finish if a sound is played in a loop.