2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-22 10:17:10 +00:00

Added ability to override volume in media audio tracks.

This commit is contained in:
23rd 2025-08-12 15:24:08 +03:00
parent 2c34838589
commit e886ca16ff
4 changed files with 21 additions and 10 deletions

View File

@ -142,7 +142,7 @@ void Track::fillFromFile(const QString &filePath) {
} }
} }
void Track::playWithLooping(bool looping) { void Track::playWithLooping(bool looping, float64 volumeOverride) {
_active = true; _active = true;
if (failed() || _samples.empty()) { if (failed() || _samples.empty()) {
finish(); finish();
@ -152,7 +152,12 @@ void Track::playWithLooping(bool looping) {
alSourceStop(_alSource); alSourceStop(_alSource);
_looping = looping; _looping = looping;
alSourcei(_alSource, AL_LOOPING, _looping ? 1 : 0); alSourcei(_alSource, AL_LOOPING, _looping ? 1 : 0);
alSourcef(_alSource, AL_GAIN, _volume); alSourcef(
_alSource,
AL_GAIN,
(volumeOverride > 0)
? volumeOverride
: _volume);
alSourcePlay(_alSource); alSourcePlay(_alSource);
_instance->trackStarted(this); _instance->trackStarted(this);
} }

View File

@ -30,11 +30,11 @@ public:
void fillFromFile(const Core::FileLocation &location); void fillFromFile(const Core::FileLocation &location);
void fillFromFile(const QString &filePath); void fillFromFile(const QString &filePath);
void playOnce() { void playOnce(float64 volumeOverride = -1) {
playWithLooping(false); playWithLooping(false, volumeOverride);
} }
void playInLoop() { void playInLoop(float64 volumeOverride = -1) {
playWithLooping(true); playWithLooping(true, volumeOverride);
} }
bool isLooping() const { bool isLooping() const {
@ -61,7 +61,7 @@ public:
private: private:
void finish(); void finish();
void ensureSourceCreated(); void ensureSourceCreated();
void playWithLooping(bool looping); void playWithLooping(bool looping, float64 volumeOverride);
not_null<Instance*> _instance; not_null<Instance*> _instance;

View File

@ -967,8 +967,11 @@ void System::notifySettingsChanged(ChangeType type) {
return _settingsChanged.fire(std::move(type)); return _settingsChanged.fire(std::move(type));
} }
void System::playSound(not_null<Main::Session*> session, DocumentId id) { void System::playSound(
lookupSound(&session->data(), id)->playOnce(); not_null<Main::Session*> session,
DocumentId id,
float64 volumeOverride) {
lookupSound(&session->data(), id)->playOnce(volumeOverride);
} }
Manager::DisplayOptions Manager::getNotificationOptions( Manager::DisplayOptions Manager::getNotificationOptions(

View File

@ -124,7 +124,10 @@ public:
[[nodiscard]] rpl::producer<ChangeType> settingsChanged() const; [[nodiscard]] rpl::producer<ChangeType> settingsChanged() const;
void notifySettingsChanged(ChangeType type); void notifySettingsChanged(ChangeType type);
void playSound(not_null<Main::Session*> session, DocumentId id); void playSound(
not_null<Main::Session*> session,
DocumentId id,
float64 volumeOverride = -1);
[[nodiscard]] QByteArray lookupSoundBytes( [[nodiscard]] QByteArray lookupSoundBytes(
not_null<Data::Session*> owner, not_null<Data::Session*> owner,
DocumentId id); DocumentId id);