mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-23 23:14:41 +00:00
Fix volume saving to settings.
This commit is contained in:
parent
6afb3f70bb
commit
846499a4fb
@ -775,16 +775,15 @@ bool Mixer::fadedStop(AudioMsgId::Type type, bool *fadedStart) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Mixer::play(const AudioMsgId &audio, crl::time positionMs) {
|
||||
setSongVolume(Global::SongVolume());
|
||||
play(audio, nullptr, positionMs);
|
||||
}
|
||||
|
||||
void Mixer::play(
|
||||
const AudioMsgId &audio,
|
||||
std::unique_ptr<ExternalSoundData> externalData,
|
||||
crl::time positionMs) {
|
||||
Expects((externalData != nullptr) == (audio.externalPlayId() != 0));
|
||||
Expects(externalData != nullptr);
|
||||
Expects(audio.externalPlayId() != 0);
|
||||
|
||||
setSongVolume(Global::SongVolume());
|
||||
setVideoVolume(Global::VideoVolume());
|
||||
|
||||
auto type = audio.type();
|
||||
AudioMsgId stopped;
|
||||
@ -1049,72 +1048,74 @@ void Mixer::resume(const AudioMsgId &audio, bool fast) {
|
||||
}
|
||||
if (current) emit updated(current);
|
||||
}
|
||||
|
||||
void Mixer::seek(AudioMsgId::Type type, crl::time positionMs) {
|
||||
QMutexLocker lock(&AudioMutex);
|
||||
|
||||
const auto current = trackForType(type);
|
||||
const auto audio = current->state.id;
|
||||
|
||||
Audio::AttachToDevice();
|
||||
const auto streamCreated = current->isStreamCreated();
|
||||
const auto position = (positionMs * current->frequency) / 1000LL;
|
||||
const auto fastSeek = [&] {
|
||||
const auto loadedStart = current->bufferedPosition;
|
||||
const auto loadedLength = current->bufferedLength;
|
||||
const auto skipBack = (current->loaded ? 0 : kDefaultFrequency);
|
||||
const auto availableEnd = loadedStart + loadedLength - skipBack;
|
||||
if (position < loadedStart) {
|
||||
return false;
|
||||
} else if (position >= availableEnd) {
|
||||
return false;
|
||||
} else if (!streamCreated) {
|
||||
return false;
|
||||
} else if (IsStoppedOrStopping(current->state.state)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}();
|
||||
if (fastSeek) {
|
||||
alSourcei(current->stream.source, AL_SAMPLE_OFFSET, position - current->bufferedPosition);
|
||||
if (!checkCurrentALError(type)) return;
|
||||
|
||||
alSourcef(current->stream.source, AL_GAIN, ComputeVolume(type));
|
||||
if (!checkCurrentALError(type)) return;
|
||||
|
||||
resetFadeStartPosition(type, position - current->bufferedPosition);
|
||||
} else {
|
||||
setStoppedState(current);
|
||||
}
|
||||
switch (current->state.state) {
|
||||
case State::Pausing:
|
||||
case State::Paused:
|
||||
case State::PausedAtEnd: {
|
||||
if (current->state.state == State::PausedAtEnd) {
|
||||
current->state.state = State::Paused;
|
||||
}
|
||||
lock.unlock();
|
||||
return resume(audio, true);
|
||||
} break;
|
||||
case State::Starting:
|
||||
case State::Resuming:
|
||||
case State::Playing: {
|
||||
current->state.state = State::Pausing;
|
||||
resetFadeStartPosition(type);
|
||||
if (type == AudioMsgId::Type::Voice) {
|
||||
emit unsuppressSong();
|
||||
}
|
||||
} break;
|
||||
case State::Stopping:
|
||||
case State::Stopped:
|
||||
case State::StoppedAtEnd:
|
||||
case State::StoppedAtError:
|
||||
case State::StoppedAtStart: {
|
||||
lock.unlock();
|
||||
} return play(audio, positionMs);
|
||||
}
|
||||
emit faderOnTimer();
|
||||
}
|
||||
//
|
||||
// Right now all the music is played in the streaming player.
|
||||
//
|
||||
//void Mixer::seek(AudioMsgId::Type type, crl::time positionMs) {
|
||||
// QMutexLocker lock(&AudioMutex);
|
||||
//
|
||||
// const auto current = trackForType(type);
|
||||
// const auto audio = current->state.id;
|
||||
//
|
||||
// Audio::AttachToDevice();
|
||||
// const auto streamCreated = current->isStreamCreated();
|
||||
// const auto position = (positionMs * current->frequency) / 1000LL;
|
||||
// const auto fastSeek = [&] {
|
||||
// const auto loadedStart = current->bufferedPosition;
|
||||
// const auto loadedLength = current->bufferedLength;
|
||||
// const auto skipBack = (current->loaded ? 0 : kDefaultFrequency);
|
||||
// const auto availableEnd = loadedStart + loadedLength - skipBack;
|
||||
// if (position < loadedStart) {
|
||||
// return false;
|
||||
// } else if (position >= availableEnd) {
|
||||
// return false;
|
||||
// } else if (!streamCreated) {
|
||||
// return false;
|
||||
// } else if (IsStoppedOrStopping(current->state.state)) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }();
|
||||
// if (fastSeek) {
|
||||
// alSourcei(current->stream.source, AL_SAMPLE_OFFSET, position - current->bufferedPosition);
|
||||
// if (!checkCurrentALError(type)) return;
|
||||
//
|
||||
// alSourcef(current->stream.source, AL_GAIN, ComputeVolume(type));
|
||||
// if (!checkCurrentALError(type)) return;
|
||||
//
|
||||
// resetFadeStartPosition(type, position - current->bufferedPosition);
|
||||
// } else {
|
||||
// setStoppedState(current);
|
||||
// }
|
||||
// switch (current->state.state) {
|
||||
// case State::Pausing:
|
||||
// case State::Paused:
|
||||
// case State::PausedAtEnd: {
|
||||
// if (current->state.state == State::PausedAtEnd) {
|
||||
// current->state.state = State::Paused;
|
||||
// }
|
||||
// lock.unlock();
|
||||
// return resume(audio, true);
|
||||
// } break;
|
||||
// case State::Starting:
|
||||
// case State::Resuming:
|
||||
// case State::Playing: {
|
||||
// current->state.state = State::Pausing;
|
||||
// resetFadeStartPosition(type);
|
||||
// if (type == AudioMsgId::Type::Voice) {
|
||||
// emit unsuppressSong();
|
||||
// }
|
||||
// } break;
|
||||
// case State::Stopping:
|
||||
// case State::Stopped:
|
||||
// case State::StoppedAtEnd:
|
||||
// case State::StoppedAtError:
|
||||
// case State::StoppedAtStart: {
|
||||
// lock.unlock();
|
||||
// } return play(audio, positionMs);
|
||||
// }
|
||||
// emit faderOnTimer();
|
||||
//}
|
||||
|
||||
void Mixer::stop(const AudioMsgId &audio) {
|
||||
AudioMsgId current;
|
||||
|
@ -128,14 +128,12 @@ class Mixer : public QObject, private base::Subscriber {
|
||||
public:
|
||||
explicit Mixer(not_null<Audio::Instance*> instance);
|
||||
|
||||
void play(const AudioMsgId &audio, crl::time positionMs = 0);
|
||||
void play(
|
||||
const AudioMsgId &audio,
|
||||
std::unique_ptr<ExternalSoundData> externalData,
|
||||
crl::time positionMs = 0);
|
||||
crl::time positionMs);
|
||||
void pause(const AudioMsgId &audio, bool fast = false);
|
||||
void resume(const AudioMsgId &audio, bool fast = false);
|
||||
void seek(AudioMsgId::Type type, crl::time positionMs); // type == AudioMsgId::Type::Song
|
||||
void stop(const AudioMsgId &audio);
|
||||
void stop(const AudioMsgId &audio, State state);
|
||||
|
||||
|
@ -556,11 +556,13 @@ void Instance::finishSeeking(AudioMsgId::Type type, float64 progress) {
|
||||
position));
|
||||
emitUpdate(type);
|
||||
}
|
||||
} else {
|
||||
const auto state = getState(type);
|
||||
if (state.id && state.length && state.frequency) {
|
||||
mixer()->seek(type, qRound(progress * state.length * 1000. / state.frequency));
|
||||
}
|
||||
//
|
||||
// Right now all music is played in streaming player.
|
||||
//} else {
|
||||
// const auto state = getState(type);
|
||||
// if (state.id && state.length && state.frequency) {
|
||||
// mixer()->seek(type, qRound(progress * state.length * 1000. / state.frequency));
|
||||
// }
|
||||
}
|
||||
}
|
||||
cancelSeeking(type);
|
||||
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "styles/style_media_player.h"
|
||||
#include "styles/style_widgets.h"
|
||||
#include "mainwindow.h"
|
||||
#include "auth_session.h"
|
||||
|
||||
namespace Media {
|
||||
namespace Player {
|
||||
@ -29,6 +30,7 @@ VolumeController::VolumeController(QWidget *parent) : TWidget(parent)
|
||||
Global::SetRememberedSongVolume(volume);
|
||||
}
|
||||
applyVolumeChange(volume);
|
||||
Auth().saveSettingsDelayed();
|
||||
});
|
||||
subscribe(Global::RefSongVolumeChanged(), [this] {
|
||||
if (!_slider->isChanging()) {
|
||||
|
@ -2297,6 +2297,11 @@ void OverlayWidget::playbackControlsVolumeChanged(float64 volume) {
|
||||
Global::SetVideoVolume(volume);
|
||||
updateMixerVideoVolume();
|
||||
Global::RefVideoVolumeChanged().notify();
|
||||
Auth().saveSettingsDelayed();
|
||||
}
|
||||
|
||||
float64 OverlayWidget::playbackControlsCurrentVolume() {
|
||||
return Global::VideoVolume();
|
||||
}
|
||||
|
||||
void OverlayWidget::playbackToggleFullScreen() {
|
||||
|
@ -163,6 +163,7 @@ private:
|
||||
void playbackControlsSeekProgress(crl::time position) override;
|
||||
void playbackControlsSeekFinished(crl::time position) override;
|
||||
void playbackControlsVolumeChanged(float64 volume) override;
|
||||
float64 playbackControlsCurrentVolume() override;
|
||||
void playbackControlsToFullScreen() override;
|
||||
void playbackControlsFromFullScreen() override;
|
||||
void playbackPauseResume();
|
||||
|
@ -19,7 +19,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
namespace Media {
|
||||
namespace View {
|
||||
|
||||
PlaybackControls::PlaybackControls(QWidget *parent, not_null<Delegate *> delegate)
|
||||
PlaybackControls::PlaybackControls(
|
||||
QWidget *parent,
|
||||
not_null<Delegate*> delegate)
|
||||
: RpWidget(parent)
|
||||
, _delegate(delegate)
|
||||
, _playPauseResume(this, st::mediaviewPlayButton)
|
||||
@ -38,7 +40,7 @@ PlaybackControls::PlaybackControls(QWidget *parent, not_null<Delegate *> delegat
|
||||
fadeUpdated(opacity);
|
||||
});
|
||||
|
||||
_volumeController->setValue(Global::VideoVolume());
|
||||
_volumeController->setValue(_delegate->playbackControlsCurrentVolume());
|
||||
_volumeController->setChangeProgressCallback([=](float64 value) {
|
||||
_delegate->playbackControlsVolumeChanged(value);
|
||||
});
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
virtual void playbackControlsSeekProgress(crl::time position) = 0;
|
||||
virtual void playbackControlsSeekFinished(crl::time position) = 0;
|
||||
virtual void playbackControlsVolumeChanged(float64 volume) = 0;
|
||||
[[nodiscard]] virtual float64 playbackControlsCurrentVolume() = 0;
|
||||
virtual void playbackControlsToFullScreen() = 0;
|
||||
virtual void playbackControlsFromFullScreen() = 0;
|
||||
};
|
||||
|
@ -50,7 +50,7 @@ QRect ContinuousSlider::getSeekRect() const {
|
||||
}
|
||||
|
||||
void ContinuousSlider::setValue(float64 value) {
|
||||
setValue(value, value);
|
||||
setValue(value, -1);
|
||||
}
|
||||
|
||||
void ContinuousSlider::setValue(float64 value, float64 receivedTill) {
|
||||
|
Loading…
Reference in New Issue
Block a user