内容表

上一话题

QSound

下一话题

QVideoDeviceSelectorControl

QSoundEffect

QSoundEffect class provides a way to play low latency sound effects. 更多

Inheritance diagram of PySide2.QtMultimedia.QSoundEffect

详细描述

This class allows you to play uncompressed audio files (typically WAV files) in a generally lower latency way, and is suitable for “feedback” type sounds in response to user actions (e.g. virtual keyboard sounds, positive or negative feedback for popup dialogs, or game sounds). If low latency is not important, consider using the QMediaPlayer class instead, since it supports a wider variety of media formats and is less resource intensive.

This example shows how a looping, somewhat quiet sound effect can be played:

QSoundEffect effect;
effect.setSource(QUrl::fromLocalFile("engine.wav"));
effect.setLoopCount(QSoundEffect::Infinite);
effect.setVolume(0.25f);
effect.play();
											

Typically the sound effect should be reused, which allows all the parsing and preparation to be done ahead of time, and only triggered when necessary. This assists with lower latency audio playback.

    MyGame()
        : m_explosion(this)
    {
        m_explosion.setSource(QUrl::fromLocalFile("explosion.wav"));
        m_explosion.setVolume(0.25f);
        // Set up click handling etc.
        connect(clickSource, &QPushButton::clicked, &m_explosion, &QSoundEffect::play);
    }
private:
    QSoundEffect m_explosion;
											

Since QSoundEffect requires slightly more resources to achieve lower latency playback, the platform may limit the number of simultaneously playing sound effects.

class QSoundEffect ( [ parent=None ] )

QSoundEffect(audioDevice[, parent=None])

param parent

QObject

param audioDevice

QAudioDeviceInfo

创建 QSoundEffect 采用给定 parent .

创建 QSoundEffect 采用给定 audioDevice and parent .

PySide2.QtMultimedia.QSoundEffect. Loop

常量

描述

QSoundEffect.Infinite

作为参数用于 setLoopCount() for infinite looping

PySide2.QtMultimedia.QSoundEffect. Status

常量

描述

QSoundEffect.Null

未设置源或源为 null。

QSoundEffect.Loading

SoundEffect 正试着加载源。

QSoundEffect.Ready

源被加载并准备播放。

QSoundEffect.Error

操作期间发生错误,譬如:源加载失败。

PySide2.QtMultimedia.QSoundEffect. category ( )
返回类型

unicode

返回当前 category for this sound effect.

Some platforms can perform different audio routing for different categories, or may allow the user to set different volume levels for different categories.

This setting will be ignored on platforms that do not support audio categories.

另请参阅

setCategory()

PySide2.QtMultimedia.QSoundEffect. categoryChanged ( )
PySide2.QtMultimedia.QSoundEffect. isLoaded ( )
返回类型

bool

Returns whether the sound effect has finished loading the source() .

PySide2.QtMultimedia.QSoundEffect. isMuted ( )
返回类型

bool

Returns whether this sound effect is muted

PySide2.QtMultimedia.QSoundEffect. isPlaying ( )
返回类型

bool

Returns true if the sound effect is currently playing, or false otherwise

PySide2.QtMultimedia.QSoundEffect. loadedChanged ( )
PySide2.QtMultimedia.QSoundEffect. loopCount ( )
返回类型

int

Returns the total number of times that this sound effect will be played before stopping.

loopsRemaining() method for the number of loops currently remaining.

另请参阅

setLoopCount()

PySide2.QtMultimedia.QSoundEffect. loopCountChanged ( )
PySide2.QtMultimedia.QSoundEffect. loopsRemaining ( )
返回类型

int

PySide2.QtMultimedia.QSoundEffect. loopsRemainingChanged ( )
PySide2.QtMultimedia.QSoundEffect. mutedChanged ( )
PySide2.QtMultimedia.QSoundEffect. play ( )

Start playback of the sound effect, looping the effect for the number of times as specified in the loops property.

PySide2.QtMultimedia.QSoundEffect. playingChanged ( )
PySide2.QtMultimedia.QSoundEffect. setCategory ( category )
参数

category – unicode

设置 category of this sound effect to category .

Some platforms can perform different audio routing for different categories, or may allow the user to set different volume levels for different categories.

This setting will be ignored on platforms that do not support audio categories.

If this setting is changed while a sound effect is playing it will only take effect when the sound effect has stopped playing.

另请参阅

category()

PySide2.QtMultimedia.QSoundEffect. setLoopCount ( loopCount )
参数

loopCount int

Set the total number of times to play this sound effect to loopCount .

Setting the loop count to 0 or 1 means the sound effect will be played only once; pass QSoundEffect::Infinite to repeat indefinitely. The loop count can be changed while the sound effect is playing, in which case it will update the remaining loops to the new loopCount .

PySide2.QtMultimedia.QSoundEffect. setMuted ( muted )
参数

muted bool

Sets whether to mute this sound effect’s playback.

muted is true, playback will be muted (silenced), and otherwise playback will occur with the currently specified volume() .

另请参阅

isMuted()

PySide2.QtMultimedia.QSoundEffect. setSource ( url )
参数

url QUrl

Set the current URL to play to url .

另请参阅

source()

PySide2.QtMultimedia.QSoundEffect. setVolume ( volume )
参数

volume qreal

Sets the sound effect volume to volume .

The volume is scaled linearly from 0.0 (silence) to 1.0 (full volume). Values outside this range will be clamped.

The default volume is 1.0 .

UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale will produce linear changes in perceived loudness, which is what a user would normally expect from a volume control. See convertVolume() 了解更多细节。

另请参阅

volume()

PySide2.QtMultimedia.QSoundEffect. source ( )
返回类型

QUrl

Returns the URL of the current source to play

另请参阅

setSource()

PySide2.QtMultimedia.QSoundEffect. sourceChanged ( )
PySide2.QtMultimedia.QSoundEffect. status ( )
返回类型

Status

Returns the current status of this sound effect.

PySide2.QtMultimedia.QSoundEffect. statusChanged ( )
PySide2.QtMultimedia.QSoundEffect. stop ( )

Stop current playback.

static PySide2.QtMultimedia.QSoundEffect. supportedMimeTypes ( )
返回类型

字符串列表

Returns a list of the supported mime types for this platform.

PySide2.QtMultimedia.QSoundEffect. volume ( )
返回类型

qreal

Returns the current volume of this sound effect, from 0.0 (silent) to 1.0 (maximum volume).

另请参阅

setVolume()

PySide2.QtMultimedia.QSoundEffect. volumeChanged ( )