本页内容

QAmbientSound Class

立体声叠加音效。更多...

标题: #include <QAmbientSound>
CMake: find_package(Qt6 REQUIRED COMPONENTS SpatialAudio)
target_link_libraries(mytarget PRIVATE Qt6::SpatialAudio)
qmake: QT += spatialaudio
继承自: QObject

公共类型

enum Loops { Infinite, Once }

属性

公共函数

QAmbientSound(QAudioEngine *engine)
bool autoPlay() const
QAudioEngine *engine() const
int loops() const
void setAutoPlay(bool autoPlay)
void setLoops(int loops)
void setSource(const QUrl &url)
void setVolume(float volume)
QUrl source() const
float volume() const

公共槽位

void pause()
void play()
void stop()

信号

详细说明

QAmbientSound 表示一种与位置和方向无关的声音。它通常用于背景声音(例如音乐),这类声音应与听者的位置和方向无关。

注意: 只有当QAudioEngine 使用OutputMode::Stereo或OutputMode::Headphone时,QAmbientSound 才处于活动状态。

成员类型文档

enum QAmbientSound::Loops

允许您使用以下值控制播放循环:

常量值说明
QAmbientSound::Infinite-1无限循环
QAmbientSound::Once1播放一次后停止

属性文档

autoPlay : bool

确定在指定音源时,声音是否应自动开始播放。

默认值为true 。

访问函数:

bool autoPlay() const
void setAutoPlay(bool autoPlay)

通知信号:

void autoPlayChanged()

loops : int

确定在播放器停止前声音播放的次数。设置为QAmbientSound::Infinite 可使当前声音无限循环播放。

默认值为1 。

访问函数:

int loops() const
void setLoops(int loops)

通知信号:

void loopsChanged()

source : QUrl

要播放的音频的源文件。

访问函数:

QUrl source() const
void setSource(const QUrl &url)

通知信号:

void sourceChanged()

volume : float

用于设置声音的音量。

0 到 1 之间的数值会降低音量,而大于 1 的数值则会提供额外的增益提升。

访问函数:

float volume() const
void setVolume(float volume)

通知信号:

void volumeChanged()

成员函数文档

[explicit] QAmbientSound::QAmbientSound(QAudioEngine *engine)

为engine 创建一个立体声声源。

注意: 调用时必须 传入一个有效的QAudioEngine

QAudioEngine *QAmbientSound::engine() const

返回与该声音关联的引擎。

[slot] void QAmbientSound::pause()

暂停声音播放。调用play()将恢复播放。

[slot] void QAmbientSound::play()

开始播放声音。如果声音已经在播放,则不执行任何操作。

[slot] void QAmbientSound::stop()

停止声音播放,并将当前位置和当前循环计数重置为0。调用play() 将从声音文件的开头开始播放。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.