mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-28 01:23:09 +00:00
Moved AudioPlayerState+position+duration+frequency to a single struct.
This commit is contained in:
parent
99b15719cf
commit
1fee0822fb
@ -4402,61 +4402,48 @@ bool HistoryDocument::updateStatusText() const {
|
||||
} else if (_data->loading()) {
|
||||
statusSize = _data->loadOffset();
|
||||
} else if (_data->loaded()) {
|
||||
if (_data->voice()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
if (audioPlayer()) {
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
}
|
||||
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
if (auto voice = Get<HistoryDocumentVoice>()) {
|
||||
bool was = voice->_playback;
|
||||
voice->ensurePlayback(this);
|
||||
if (!was || playingPosition != voice->_playback->_position) {
|
||||
float64 prg = playingDuration ? snap(float64(playingPosition) / playingDuration, 0., 1.) : 0.;
|
||||
if (voice->_playback->_position < playingPosition) {
|
||||
voice->_playback->a_progress.start(prg);
|
||||
} else {
|
||||
voice->_playback->a_progress = anim::fvalue(0., prg);
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
if (audioPlayer()) {
|
||||
if (_data->voice()) {
|
||||
AudioMsgId playing;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice);
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
if (auto voice = Get<HistoryDocumentVoice>()) {
|
||||
bool was = voice->_playback;
|
||||
voice->ensurePlayback(this);
|
||||
if (!was || playbackState.position != voice->_playback->_position) {
|
||||
float64 prg = playbackState.duration ? snap(float64(playbackState.position) / playbackState.duration, 0., 1.) : 0.;
|
||||
if (voice->_playback->_position < playbackState.position) {
|
||||
voice->_playback->a_progress.start(prg);
|
||||
} else {
|
||||
voice->_playback->a_progress = anim::fvalue(0., prg);
|
||||
}
|
||||
voice->_playback->_position = playbackState.position;
|
||||
voice->_playback->_a_progress.start();
|
||||
}
|
||||
voice->_playback->_position = playingPosition;
|
||||
voice->_playback->_a_progress.start();
|
||||
}
|
||||
|
||||
statusSize = -1 - (playbackState.position / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playbackState.duration / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
|
||||
} else {
|
||||
if (auto voice = Get<HistoryDocumentVoice>()) {
|
||||
voice->checkPlaybackFinished();
|
||||
}
|
||||
}
|
||||
|
||||
statusSize = -1 - (playingPosition / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playingDuration / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting);
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
if (auto voice = Get<HistoryDocumentVoice>()) {
|
||||
voice->checkPlaybackFinished();
|
||||
} else if (_data->song()) {
|
||||
AudioMsgId playing;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playbackState.position / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playbackState.duration / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
|
||||
} else {
|
||||
}
|
||||
if (!showPause && (playing == AudioMsgId(_data, _parent->fullId())) && App::main() && App::main()->player()->seekingSong(playing)) {
|
||||
showPause = true;
|
||||
}
|
||||
}
|
||||
} else if (_data->song()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
if (audioPlayer()) {
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
}
|
||||
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playingPosition / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playingDuration / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting);
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
}
|
||||
if (!showPause && (playing == AudioMsgId(_data, _parent->fullId())) && App::main() && App::main()->player()->seekingSong(playing)) {
|
||||
showPause = true;
|
||||
}
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
}
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
|
@ -854,39 +854,29 @@ bool File::updateStatusText() const {
|
||||
statusSize = document->loadOffset();
|
||||
} else if (document->loaded()) {
|
||||
if (document->voice()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
if (audioPlayer()) {
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
}
|
||||
|
||||
if (playing == AudioMsgId(document, FullMsgId()) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playingPosition / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playingDuration / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting);
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
AudioMsgId playing;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice);
|
||||
if (playing == AudioMsgId(document, FullMsgId()) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playbackState.position / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playbackState.duration / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
|
||||
}
|
||||
}
|
||||
} else if (document->song()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
if (audioPlayer()) {
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
}
|
||||
|
||||
if (playing == AudioMsgId(document, FullMsgId()) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playingPosition / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playingDuration / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting);
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
}
|
||||
if (!showPause && (playing == AudioMsgId(document, FullMsgId())) && App::main() && App::main()->player()->seekingSong(playing)) {
|
||||
showPause = true;
|
||||
AudioMsgId playing;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == AudioMsgId(document, FullMsgId()) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playbackState.position / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playbackState.duration / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
|
||||
}
|
||||
if (!showPause && (playing == AudioMsgId(document, FullMsgId())) && App::main() && App::main()->player()->seekingSong(playing)) {
|
||||
showPause = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
|
@ -91,7 +91,6 @@ MainWidget::MainWidget(MainWindow *window) : TWidget(window)
|
||||
connect(&updateNotifySettingTimer, SIGNAL(timeout()), this, SLOT(onUpdateNotifySettings()));
|
||||
if (audioPlayer()) {
|
||||
connect(audioPlayer(), SIGNAL(updated(const AudioMsgId&)), this, SLOT(audioPlayProgress(const AudioMsgId&)));
|
||||
connect(audioPlayer(), SIGNAL(stopped(const AudioMsgId&)), this, SLOT(audioPlayProgress(const AudioMsgId&)));
|
||||
}
|
||||
connect(&_updateMutedTimer, SIGNAL(timeout()), this, SLOT(onUpdateMuted()));
|
||||
connect(&_viewsIncrementTimer, SIGNAL(timeout()), this, SLOT(onViewsIncrement()));
|
||||
@ -1530,13 +1529,14 @@ void MainWidget::ui_autoplayMediaInlineAsync(qint32 channelId, qint32 msgId) {
|
||||
}
|
||||
|
||||
void MainWidget::audioPlayProgress(const AudioMsgId &audioId) {
|
||||
if (audioId.type() == AudioMsgId::Type::Video) {
|
||||
return;
|
||||
}
|
||||
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
audioPlayer()->currentState(&playing, audioId.type(), &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
if (playing == audioId && playingState == AudioPlayerStoppedAtStart) {
|
||||
playingState = AudioPlayerStopped;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, audioId.type());
|
||||
if (playing == audioId && playbackState.state == AudioPlayerStoppedAtStart) {
|
||||
playbackState.state = AudioPlayerStopped;
|
||||
audioPlayer()->clearStoppedAtStart(audioId);
|
||||
|
||||
DocumentData *audio = audioId.audio();
|
||||
@ -1551,9 +1551,9 @@ void MainWidget::audioPlayProgress(const AudioMsgId &audioId) {
|
||||
}
|
||||
|
||||
if (playing == audioId && audioId.type() == AudioMsgId::Type::Song) {
|
||||
_player->updateState(playing, playingState, playingPosition, playingDuration, playingFrequency);
|
||||
_player->updateState(playing, playbackState);
|
||||
|
||||
if (!(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
if (!(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
if (!_player->isOpened()) {
|
||||
_player->openPlayer();
|
||||
if (_player->isHidden() && !_a_show.animating()) {
|
||||
@ -1609,12 +1609,9 @@ void MainWidget::documentLoadProgress(FileLoader *loader) {
|
||||
|
||||
if (!document->loaded() && document->loading() && document->song() && audioPlayer()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing.audio() == document && !_player->isHidden()) {
|
||||
_player->updateState(playing, playingState, playingPosition, playingDuration, playingFrequency);
|
||||
_player->updateState(playing, playbackState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -263,12 +263,10 @@ void AudioPlayer::AudioMsg::clear() {
|
||||
audio = AudioMsgId();
|
||||
file = FileLocation();
|
||||
data = QByteArray();
|
||||
position = duration = 0;
|
||||
frequency = AudioVoiceMsgFrequency;
|
||||
playbackState = defaultState();
|
||||
skipStart = skipEnd = 0;
|
||||
loading = false;
|
||||
started = 0;
|
||||
state = AudioPlayerStopped;
|
||||
if (alIsSource(source)) {
|
||||
alSourceStop(source);
|
||||
}
|
||||
@ -305,7 +303,7 @@ _loader(new AudioPlayerLoaders(&_loaderThread)) {
|
||||
connect(_fader, SIGNAL(playPositionUpdated(const AudioMsgId&)), this, SIGNAL(updated(const AudioMsgId&)));
|
||||
connect(_fader, SIGNAL(audioStopped(const AudioMsgId&)), this, SLOT(onStopped(const AudioMsgId&)));
|
||||
connect(_fader, SIGNAL(error(const AudioMsgId&)), this, SLOT(onError(const AudioMsgId&)));
|
||||
connect(this, SIGNAL(stoppedOnError(const AudioMsgId&)), this, SIGNAL(stopped(const AudioMsgId&)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(stoppedOnError(const AudioMsgId&)), this, SIGNAL(updated(const AudioMsgId&)), Qt::QueuedConnection);
|
||||
_loaderThread.start();
|
||||
_faderThread.start();
|
||||
}
|
||||
@ -350,7 +348,7 @@ void AudioPlayer::onError(const AudioMsgId &audio) {
|
||||
}
|
||||
|
||||
void AudioPlayer::onStopped(const AudioMsgId &audio) {
|
||||
emit stopped(audio);
|
||||
emit updated(audio);
|
||||
if (audio.type() == AudioMsgId::Type::Voice) {
|
||||
emit unsuppressSong();
|
||||
}
|
||||
@ -399,7 +397,7 @@ bool AudioPlayer::updateCurrentStarted(AudioMsgId::Type type, int32 pos) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
data->started = data->position = pos + data->skipStart;
|
||||
data->started = data->playbackState.position = pos + data->skipStart;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -407,16 +405,16 @@ bool AudioPlayer::fadedStop(AudioMsgId::Type type, bool *fadedStart) {
|
||||
auto current = dataForType(type);
|
||||
if (!current) return false;
|
||||
|
||||
switch (current->state) {
|
||||
switch (current->playbackState.state) {
|
||||
case AudioPlayerStarting:
|
||||
case AudioPlayerResuming:
|
||||
case AudioPlayerPlaying:
|
||||
current->state = AudioPlayerFinishing;
|
||||
current->playbackState.state = AudioPlayerFinishing;
|
||||
updateCurrentStarted(type);
|
||||
if (fadedStart) *fadedStart = true;
|
||||
break;
|
||||
case AudioPlayerPausing:
|
||||
current->state = AudioPlayerFinishing;
|
||||
current->playbackState.state = AudioPlayerFinishing;
|
||||
if (fadedStart) *fadedStart = true;
|
||||
break;
|
||||
case AudioPlayerPaused:
|
||||
@ -473,7 +471,7 @@ void AudioPlayer::play(const AudioMsgId &audio, int64 position) {
|
||||
onError(audio);
|
||||
}
|
||||
} else {
|
||||
current->state = fadedStart ? AudioPlayerStarting : AudioPlayerPlaying;
|
||||
current->playbackState.state = fadedStart ? AudioPlayerStarting : AudioPlayerPlaying;
|
||||
current->loading = true;
|
||||
emit loaderOnStart(audio, position);
|
||||
if (type == AudioMsgId::Type::Voice) {
|
||||
@ -507,7 +505,7 @@ void AudioPlayer::playFromVideo(const AudioMsgId &audio, int64 position, std_::u
|
||||
current->videoData = std_::move(data);
|
||||
_loader->startFromVideo(current->videoData->videoPlayId);
|
||||
|
||||
current->state = AudioPlayerPlaying;
|
||||
current->playbackState.state = AudioPlayerPlaying;
|
||||
current->loading = true;
|
||||
emit loaderOnStart(audio, position);
|
||||
}
|
||||
@ -539,19 +537,19 @@ void AudioPlayer::pauseresume(AudioMsgId::Type type, bool fast) {
|
||||
case AudioMsgId::Type::Song: suppressGain = suppressSongGain * cSongVolume(); break;
|
||||
}
|
||||
|
||||
switch (current->state) {
|
||||
switch (current->playbackState.state) {
|
||||
case AudioPlayerPausing:
|
||||
case AudioPlayerPaused:
|
||||
case AudioPlayerPausedAtEnd: {
|
||||
if (current->state == AudioPlayerPaused) {
|
||||
if (current->playbackState.state == AudioPlayerPaused) {
|
||||
updateCurrentStarted(type);
|
||||
} else if (current->state == AudioPlayerPausedAtEnd) {
|
||||
} else if (current->playbackState.state == AudioPlayerPausedAtEnd) {
|
||||
if (alIsSource(current->source)) {
|
||||
alSourcei(current->source, AL_SAMPLE_OFFSET, qMax(current->position - current->skipStart, 0LL));
|
||||
alSourcei(current->source, AL_SAMPLE_OFFSET, qMax(current->playbackState.position - current->skipStart, 0LL));
|
||||
if (!checkCurrentALError(type)) return;
|
||||
}
|
||||
}
|
||||
current->state = fast ? AudioPlayerPlaying : AudioPlayerResuming;
|
||||
current->playbackState.state = fast ? AudioPlayerPlaying : AudioPlayerResuming;
|
||||
|
||||
ALint state = AL_INITIAL;
|
||||
alGetSourcei(current->source, AL_SOURCE_STATE, &state);
|
||||
@ -571,11 +569,11 @@ void AudioPlayer::pauseresume(AudioMsgId::Type type, bool fast) {
|
||||
case AudioPlayerStarting:
|
||||
case AudioPlayerResuming:
|
||||
case AudioPlayerPlaying:
|
||||
current->state = AudioPlayerPausing;
|
||||
current->playbackState.state = AudioPlayerPausing;
|
||||
updateCurrentStarted(type);
|
||||
if (type == AudioMsgId::Type::Voice) emit unsuppressSong();
|
||||
break;
|
||||
case AudioPlayerFinishing: current->state = AudioPlayerPausing; break;
|
||||
case AudioPlayerFinishing: current->playbackState.state = AudioPlayerPausing; break;
|
||||
}
|
||||
emit faderOnTimer();
|
||||
}
|
||||
@ -593,7 +591,7 @@ void AudioPlayer::seek(int64 position) {
|
||||
auto audio = current->audio;
|
||||
|
||||
bool isSource = alIsSource(current->source);
|
||||
bool fastSeek = (position >= current->skipStart && position < current->duration - current->skipEnd - (current->skipEnd ? AudioVoiceMsgFrequency : 0));
|
||||
bool fastSeek = (position >= current->skipStart && position < current->playbackState.duration - current->skipEnd - (current->skipEnd ? AudioVoiceMsgFrequency : 0));
|
||||
if (fastSeek && isSource) {
|
||||
alSourcei(current->source, AL_SAMPLE_OFFSET, position - current->skipStart);
|
||||
if (!checkCurrentALError(type)) return;
|
||||
@ -604,12 +602,12 @@ void AudioPlayer::seek(int64 position) {
|
||||
setStoppedState(current);
|
||||
if (isSource) alSourceStop(current->source);
|
||||
}
|
||||
switch (current->state) {
|
||||
switch (current->playbackState.state) {
|
||||
case AudioPlayerPausing:
|
||||
case AudioPlayerPaused:
|
||||
case AudioPlayerPausedAtEnd: {
|
||||
if (current->state == AudioPlayerPausedAtEnd) {
|
||||
current->state = AudioPlayerPaused;
|
||||
if (current->playbackState.state == AudioPlayerPausedAtEnd) {
|
||||
current->playbackState.state = AudioPlayerPaused;
|
||||
}
|
||||
lock.unlock();
|
||||
return pauseresume(type, true);
|
||||
@ -617,7 +615,7 @@ void AudioPlayer::seek(int64 position) {
|
||||
case AudioPlayerStarting:
|
||||
case AudioPlayerResuming:
|
||||
case AudioPlayerPlaying:
|
||||
current->state = AudioPlayerPausing;
|
||||
current->playbackState.state = AudioPlayerPausing;
|
||||
updateCurrentStarted(type);
|
||||
if (type == AudioMsgId::Type::Voice) emit unsuppressSong();
|
||||
break;
|
||||
@ -683,31 +681,24 @@ void AudioPlayer::stopAndClear() {
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPlayer::currentState(AudioMsgId *audio, AudioMsgId::Type type, AudioPlayerState *state, int64 *position, int64 *duration, int32 *frequency) {
|
||||
AudioPlaybackState AudioPlayer::currentState(AudioMsgId *audio, AudioMsgId::Type type) {
|
||||
QMutexLocker lock(&playerMutex);
|
||||
auto current = dataForType(type);
|
||||
if (!current) return;
|
||||
if (!current) return AudioPlaybackState();
|
||||
|
||||
if (audio) *audio = current->audio;
|
||||
return currentState(current, state, position, duration, frequency);
|
||||
}
|
||||
|
||||
void AudioPlayer::currentState(AudioMsg *current, AudioPlayerState *state, int64 *position, int64 *duration, int32 *frequency) {
|
||||
if (state) *state = current->state;
|
||||
if (position) *position = current->position;
|
||||
if (duration) *duration = current->duration;
|
||||
if (frequency) *frequency = current->frequency;
|
||||
return current->playbackState;
|
||||
}
|
||||
|
||||
void AudioPlayer::setStoppedState(AudioMsg *current, AudioPlayerState state) {
|
||||
current->state = state;
|
||||
current->position = 0;
|
||||
current->playbackState.state = state;
|
||||
current->playbackState.position = 0;
|
||||
}
|
||||
|
||||
void AudioPlayer::clearStoppedAtStart(const AudioMsgId &audio) {
|
||||
QMutexLocker lock(&playerMutex);
|
||||
auto data = dataForType(audio.type());
|
||||
if (data && data->audio == audio && data->state == AudioPlayerStoppedAtStart) {
|
||||
if (data && data->audio == audio && data->playbackState.state == AudioPlayerStoppedAtStart) {
|
||||
setStoppedState(data);
|
||||
}
|
||||
}
|
||||
@ -843,7 +834,7 @@ void AudioPlayerFader::onTimer() {
|
||||
|
||||
auto updatePlayback = [this, voice, &hasPlaying, &hasFading](AudioMsgId::Type type, int index, float64 suppressGain, bool suppressGainChanged) {
|
||||
auto data = voice->dataForType(type, index);
|
||||
if ((data->state & AudioPlayerStoppedMask) || data->state == AudioPlayerPaused || !data->source) return;
|
||||
if ((data->playbackState.state & AudioPlayerStoppedMask) || data->playbackState.state == AudioPlayerPaused || !data->source) return;
|
||||
|
||||
int32 emitSignals = updateOnePlayback(data, hasPlaying, hasFading, suppressGain, suppressGainChanged);
|
||||
if (emitSignals & EmitError) emit error(data->audio);
|
||||
@ -894,7 +885,7 @@ int32 AudioPlayerFader::updateOnePlayback(AudioPlayer::AudioMsg *m, bool &hasPla
|
||||
if (!_checkALError()) { setStoppedState(m, AudioPlayerStoppedAtError); return EmitError; }
|
||||
|
||||
int32 emitSignals = 0;
|
||||
switch (m->state) {
|
||||
switch (m->playbackState.state) {
|
||||
case AudioPlayerFinishing:
|
||||
case AudioPlayerPausing:
|
||||
case AudioPlayerStarting:
|
||||
@ -914,17 +905,17 @@ int32 AudioPlayerFader::updateOnePlayback(AudioPlayer::AudioMsg *m, bool &hasPla
|
||||
alSourcef(m->source, AL_GAIN, 1);
|
||||
if (!_checkALError()) { setStoppedState(m, AudioPlayerStoppedAtError); return EmitError; }
|
||||
}
|
||||
if (m->state == AudioPlayerPausing) {
|
||||
m->state = AudioPlayerPausedAtEnd;
|
||||
if (m->playbackState.state == AudioPlayerPausing) {
|
||||
m->playbackState.state = AudioPlayerPausedAtEnd;
|
||||
} else {
|
||||
setStoppedState(m, AudioPlayerStoppedAtEnd);
|
||||
}
|
||||
emitSignals |= EmitStopped;
|
||||
} else if (1000 * (pos + m->skipStart - m->started) >= AudioFadeDuration * m->frequency) {
|
||||
} else if (1000 * (pos + m->skipStart - m->started) >= AudioFadeDuration * m->playbackState.frequency) {
|
||||
fading = false;
|
||||
alSourcef(m->source, AL_GAIN, 1. * suppressGain);
|
||||
if (!_checkALError()) { setStoppedState(m, AudioPlayerStoppedAtError); return EmitError; }
|
||||
switch (m->state) {
|
||||
switch (m->playbackState.state) {
|
||||
case AudioPlayerFinishing:
|
||||
alSourceStop(m->source);
|
||||
if (!_checkALError()) { setStoppedState(m, AudioPlayerStoppedAtError); return EmitError; }
|
||||
@ -934,17 +925,17 @@ int32 AudioPlayerFader::updateOnePlayback(AudioPlayer::AudioMsg *m, bool &hasPla
|
||||
case AudioPlayerPausing:
|
||||
alSourcePause(m->source);
|
||||
if (!_checkALError()) { setStoppedState(m, AudioPlayerStoppedAtError); return EmitError; }
|
||||
m->state = AudioPlayerPaused;
|
||||
m->playbackState.state = AudioPlayerPaused;
|
||||
break;
|
||||
case AudioPlayerStarting:
|
||||
case AudioPlayerResuming:
|
||||
m->state = AudioPlayerPlaying;
|
||||
m->playbackState.state = AudioPlayerPlaying;
|
||||
playing = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
float64 newGain = 1000. * (pos + m->skipStart - m->started) / (AudioFadeDuration * m->frequency);
|
||||
if (m->state == AudioPlayerPausing || m->state == AudioPlayerFinishing) {
|
||||
float64 newGain = 1000. * (pos + m->skipStart - m->started) / (AudioFadeDuration * m->playbackState.frequency);
|
||||
if (m->playbackState.state == AudioPlayerPausing || m->playbackState.state == AudioPlayerFinishing) {
|
||||
newGain = 1. - newGain;
|
||||
}
|
||||
alSourcef(m->source, AL_GAIN, newGain * suppressGain);
|
||||
@ -966,12 +957,12 @@ int32 AudioPlayerFader::updateOnePlayback(AudioPlayer::AudioMsg *m, bool &hasPla
|
||||
if (!_checkALError()) { setStoppedState(m, AudioPlayerStoppedAtError); return EmitError; }
|
||||
}
|
||||
}
|
||||
if (state == AL_PLAYING && pos + m->skipStart - m->position >= AudioCheckPositionDelta) {
|
||||
m->position = pos + m->skipStart;
|
||||
if (state == AL_PLAYING && pos + m->skipStart - m->playbackState.position >= AudioCheckPositionDelta) {
|
||||
m->playbackState.position = pos + m->skipStart;
|
||||
emitSignals |= EmitPositionUpdated;
|
||||
}
|
||||
if (playing || m->state == AudioPlayerStarting || m->state == AudioPlayerResuming) {
|
||||
if (!m->loading && m->skipEnd > 0 && m->position + AudioPreloadSamples + m->skipEnd > m->duration) {
|
||||
if (playing || m->playbackState.state == AudioPlayerStarting || m->playbackState.state == AudioPlayerResuming) {
|
||||
if (!m->loading && m->skipEnd > 0 && m->playbackState.position + AudioPreloadSamples + m->skipEnd > m->playbackState.duration) {
|
||||
m->loading = true;
|
||||
emitSignals |= EmitNeedToPreload;
|
||||
}
|
||||
@ -983,8 +974,8 @@ int32 AudioPlayerFader::updateOnePlayback(AudioPlayer::AudioMsg *m, bool &hasPla
|
||||
}
|
||||
|
||||
void AudioPlayerFader::setStoppedState(AudioPlayer::AudioMsg *m, AudioPlayerState state) {
|
||||
m->state = state;
|
||||
m->position = 0;
|
||||
m->playbackState.state = state;
|
||||
m->playbackState.position = 0;
|
||||
}
|
||||
|
||||
void AudioPlayerFader::onPauseTimer() {
|
||||
|
@ -48,12 +48,17 @@ class AudioPlayerLoaders;
|
||||
|
||||
struct VideoSoundData;
|
||||
struct VideoSoundPart;
|
||||
struct AudioPlaybackState {
|
||||
AudioPlayerState state = AudioPlayerStopped;
|
||||
int64 position = 0;
|
||||
int64 duration = 0;
|
||||
int32 frequency = 0;
|
||||
};
|
||||
|
||||
class AudioPlayer : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
AudioPlayer();
|
||||
|
||||
void play(const AudioMsgId &audio, int64 position = 0);
|
||||
@ -64,10 +69,11 @@ public:
|
||||
// Video player audio stream interface.
|
||||
void playFromVideo(const AudioMsgId &audio, int64 position, std_::unique_ptr<VideoSoundData> &&data);
|
||||
void feedFromVideo(VideoSoundPart &&part);
|
||||
AudioPlaybackState getStateForVideo(uint64 playId);
|
||||
|
||||
void stopAndClear();
|
||||
|
||||
void currentState(AudioMsgId *audio, AudioMsgId::Type type, AudioPlayerState *state = 0, int64 *position = 0, int64 *duration = 0, int32 *frequency = 0);
|
||||
AudioPlaybackState currentState(AudioMsgId *audio, AudioMsgId::Type type);
|
||||
|
||||
void clearStoppedAtStart(const AudioMsgId &audio);
|
||||
|
||||
@ -76,14 +82,11 @@ public:
|
||||
~AudioPlayer();
|
||||
|
||||
public slots:
|
||||
|
||||
void onError(const AudioMsgId &audio);
|
||||
void onStopped(const AudioMsgId &audio);
|
||||
|
||||
signals:
|
||||
|
||||
void updated(const AudioMsgId &audio);
|
||||
void stopped(const AudioMsgId &audio);
|
||||
void stoppedOnError(const AudioMsgId &audio);
|
||||
void loaderOnStart(const AudioMsgId &audio, qint64 position);
|
||||
void loaderOnCancel(const AudioMsgId &audio);
|
||||
@ -97,7 +100,6 @@ signals:
|
||||
void songVolumeChanged();
|
||||
|
||||
private:
|
||||
|
||||
bool fadedStop(AudioMsgId::Type type, bool *fadedStart = 0);
|
||||
bool updateCurrentStarted(AudioMsgId::Type type, int32 pos = -1);
|
||||
bool checkCurrentALError(AudioMsgId::Type type);
|
||||
@ -109,14 +111,11 @@ private:
|
||||
|
||||
FileLocation file;
|
||||
QByteArray data;
|
||||
int64 position = 0;
|
||||
int64 duration = 0;
|
||||
int32 frequency = AudioVoiceMsgFrequency;
|
||||
AudioPlaybackState playbackState = defaultState();
|
||||
int64 skipStart = 0;
|
||||
int64 skipEnd = 0;
|
||||
bool loading = false;
|
||||
int64 started = 0;
|
||||
AudioPlayerState state = AudioPlayerStopped;
|
||||
|
||||
uint32 source = 0;
|
||||
int32 nextBuffer = 0;
|
||||
@ -124,9 +123,16 @@ private:
|
||||
int64 samplesCount[3] = { 0 };
|
||||
|
||||
std_::unique_ptr<VideoSoundData> videoData;
|
||||
|
||||
private:
|
||||
static AudioPlaybackState defaultState() {
|
||||
AudioPlaybackState result;
|
||||
result.frequency = AudioVoiceMsgFrequency;
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void currentState(AudioMsg *current, AudioPlayerState *state, int64 *position, int64 *duration, int32 *frequency);
|
||||
void setStoppedState(AudioMsg *current, AudioPlayerState state = AudioPlayerStopped);
|
||||
|
||||
AudioMsg *dataForType(AudioMsgId::Type type, int index = -1); // -1 uses currentIndex(type)
|
||||
@ -141,6 +147,8 @@ private:
|
||||
AudioMsg _songData[AudioSimultaneousLimit];
|
||||
|
||||
AudioMsg _videoData;
|
||||
uint64 _lastVideoPlayId;
|
||||
AudioPlaybackState _lastVideoPlaybackState;
|
||||
|
||||
QMutex _mutex;
|
||||
|
||||
|
@ -112,8 +112,8 @@ AudioMsgId AudioPlayerLoaders::clear(AudioMsgId::Type type) {
|
||||
}
|
||||
|
||||
void AudioPlayerLoaders::setStoppedState(AudioPlayer::AudioMsg *m, AudioPlayerState state) {
|
||||
m->state = state;
|
||||
m->position = 0;
|
||||
m->playbackState.state = state;
|
||||
m->playbackState.position = 0;
|
||||
}
|
||||
|
||||
void AudioPlayerLoaders::emitError(AudioMsgId::Type type) {
|
||||
@ -153,7 +153,7 @@ void AudioPlayerLoaders::loadData(AudioMsgId audio, qint64 position) {
|
||||
{
|
||||
QMutexLocker lock(internal::audioPlayerMutex());
|
||||
AudioPlayer::AudioMsg *m = checkLoader(type);
|
||||
if (m) m->state = AudioPlayerStoppedAtStart;
|
||||
if (m) m->playbackState.state = AudioPlayerStoppedAtStart;
|
||||
}
|
||||
emitError(type);
|
||||
return;
|
||||
@ -200,8 +200,8 @@ void AudioPlayerLoaders::loadData(AudioMsgId audio, qint64 position) {
|
||||
m->nextBuffer = 0;
|
||||
}
|
||||
m->skipStart = position;
|
||||
m->skipEnd = m->duration - position;
|
||||
m->position = 0;
|
||||
m->skipEnd = m->playbackState.duration - position;
|
||||
m->playbackState.position = 0;
|
||||
m->started = 0;
|
||||
}
|
||||
if (samplesCount) {
|
||||
@ -280,12 +280,12 @@ void AudioPlayerLoaders::loadData(AudioMsgId audio, qint64 position) {
|
||||
|
||||
if (finished) {
|
||||
m->skipEnd = 0;
|
||||
m->duration = m->skipStart + m->samplesCount[0] + m->samplesCount[1] + m->samplesCount[2];
|
||||
m->playbackState.duration = m->skipStart + m->samplesCount[0] + m->samplesCount[1] + m->samplesCount[2];
|
||||
clear(type);
|
||||
}
|
||||
|
||||
m->loading = false;
|
||||
if (m->state == AudioPlayerResuming || m->state == AudioPlayerPlaying || m->state == AudioPlayerStarting) {
|
||||
if (m->playbackState.state == AudioPlayerResuming || m->playbackState.state == AudioPlayerPlaying || m->playbackState.state == AudioPlayerStarting) {
|
||||
ALint state = AL_INITIAL;
|
||||
alGetSourcei(m->source, AL_SOURCE_STATE, &state);
|
||||
if (internal::audioCheckError()) {
|
||||
@ -356,7 +356,7 @@ AudioPlayerLoader *AudioPlayerLoaders::setupLoader(const AudioMsgId &audio, Setu
|
||||
|
||||
if (audio.type() == AudioMsgId::Type::Video) {
|
||||
if (!data->videoData) {
|
||||
data->state = AudioPlayerStoppedAtError;
|
||||
data->playbackState.state = AudioPlayerStoppedAtError;
|
||||
emit error(audio);
|
||||
LOG(("Audio Error: video sound data not ready"));
|
||||
return nullptr;
|
||||
@ -369,17 +369,17 @@ AudioPlayerLoader *AudioPlayerLoaders::setupLoader(const AudioMsgId &audio, Setu
|
||||
}
|
||||
|
||||
if (!l->open(position)) {
|
||||
data->state = AudioPlayerStoppedAtStart;
|
||||
data->playbackState.state = AudioPlayerStoppedAtStart;
|
||||
return nullptr;
|
||||
}
|
||||
int64 duration = l->duration();
|
||||
if (duration <= 0) {
|
||||
data->state = AudioPlayerStoppedAtStart;
|
||||
data->playbackState.state = AudioPlayerStoppedAtStart;
|
||||
return nullptr;
|
||||
}
|
||||
data->duration = duration;
|
||||
data->frequency = l->frequency();
|
||||
if (!data->frequency) data->frequency = AudioVoiceMsgFrequency;
|
||||
data->playbackState.duration = duration;
|
||||
data->playbackState.frequency = l->frequency();
|
||||
if (!data->playbackState.frequency) data->playbackState.frequency = AudioVoiceMsgFrequency;
|
||||
err = SetupNoErrorStarted;
|
||||
} else {
|
||||
if (!data->skipEnd) {
|
||||
|
@ -35,7 +35,6 @@ namespace internal {
|
||||
|
||||
class FFMpegReaderImplementation : public ReaderImplementation {
|
||||
public:
|
||||
|
||||
FFMpegReaderImplementation(FileLocation *location, QByteArray *data);
|
||||
|
||||
bool readNextFrame() override;
|
||||
|
@ -26,7 +26,6 @@ class MediaView : public TWidget, public RPCSender, public ClickHandlerHost {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
MediaView();
|
||||
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
@ -83,7 +82,6 @@ public:
|
||||
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
|
||||
|
||||
public slots:
|
||||
|
||||
void onHideControls(bool force = false);
|
||||
void onDropdownHiding();
|
||||
|
||||
@ -109,7 +107,6 @@ public slots:
|
||||
void updateImage();
|
||||
|
||||
private:
|
||||
|
||||
void displayPhoto(PhotoData *photo, HistoryItem *item);
|
||||
void displayDocument(DocumentData *doc, HistoryItem *item);
|
||||
void findCurrent();
|
||||
|
@ -556,20 +556,15 @@ bool Voice::updateStatusText() const {
|
||||
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
|
||||
statusSize = FileStatusSizeFailed;
|
||||
} else if (_data->loaded()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
if (audioPlayer()) {
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
}
|
||||
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playingPosition / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playingDuration / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting);
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
AudioMsgId playing;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice);
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playbackState.position / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playbackState.duration / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
@ -865,23 +860,18 @@ bool Document::updateStatusText() const {
|
||||
statusSize = _data->loadOffset();
|
||||
} else if (_data->loaded()) {
|
||||
if (_data->song()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
if (audioPlayer()) {
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
}
|
||||
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playingPosition / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playingDuration / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting);
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
}
|
||||
if (!showPause && (playing == AudioMsgId(_data, _parent->fullId())) && App::main() && App::main()->player()->seekingSong(playing)) {
|
||||
showPause = true;
|
||||
AudioMsgId playing;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == AudioMsgId(_data, _parent->fullId()) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
statusSize = -1 - (playbackState.position / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency));
|
||||
realDuration = playbackState.duration / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
showPause = (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
|
||||
}
|
||||
if (!showPause && (playing == AudioMsgId(_data, _parent->fullId())) && App::main() && App::main()->player()->seekingSong(playing)) {
|
||||
showPause = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
|
@ -2092,8 +2092,7 @@ int32 OverviewWidget::lastScrollTop() const {
|
||||
int32 OverviewWidget::countBestScroll() const {
|
||||
if (type() == OverviewMusicFiles && audioPlayer()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState);
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing) {
|
||||
int32 top = _inner.itemTop(playing.contextId());
|
||||
if (top >= 0) {
|
||||
|
@ -169,18 +169,15 @@ void PlayerWidget::mousePressEvent(QMouseEvent *e) {
|
||||
rtlupdate(_volumeRect);
|
||||
} else if (_over == OverPlayback) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
if (playing == _song && playingDuration) {
|
||||
if (playingState == AudioPlayerPlaying || playingState == AudioPlayerStarting || playingState == AudioPlayerResuming) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == _song && playbackState.duration) {
|
||||
if (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerStarting || playbackState.state == AudioPlayerResuming) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Song);
|
||||
}
|
||||
_down = OverPlayback;
|
||||
_downProgress = snap((pos.x() - _playbackRect.x()) / float64(_playbackRect.width()), 0., 1.);
|
||||
_downDuration = playingDuration;
|
||||
_downFrequency = (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
_downDuration = playbackState.duration;
|
||||
_downFrequency = (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
|
||||
rtlupdate(_playbackRect);
|
||||
updateDownTime();
|
||||
@ -444,12 +441,9 @@ void PlayerWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||
} else if (_down == OverPlayback) {
|
||||
mouseMoveEvent(e);
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
if (playing == _song && playingDuration) {
|
||||
_downDuration = playingDuration;
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == _song && playbackState.duration) {
|
||||
_downDuration = playbackState.duration;
|
||||
audioPlayer()->seek(qRound(_downProgress * _downDuration));
|
||||
|
||||
_showPause = true;
|
||||
@ -468,10 +462,9 @@ void PlayerWidget::playPressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState);
|
||||
if (playing == _song && !(playingState & AudioPlayerStoppedMask)) {
|
||||
if (playingState == AudioPlayerPausing || playingState == AudioPlayerPaused || playingState == AudioPlayerPausedAtEnd) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == _song && !(playbackState.state & AudioPlayerStoppedMask)) {
|
||||
if (playbackState.state == AudioPlayerPausing || playbackState.state == AudioPlayerPaused || playbackState.state == AudioPlayerPausedAtEnd) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Song);
|
||||
}
|
||||
} else {
|
||||
@ -484,10 +477,9 @@ void PlayerWidget::pausePressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState);
|
||||
if (playing == _song && !(playingState & AudioPlayerStoppedMask)) {
|
||||
if (playingState == AudioPlayerStarting || playingState == AudioPlayerResuming || playingState == AudioPlayerPlaying || playingState == AudioPlayerFinishing) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == _song && !(playbackState.state & AudioPlayerStoppedMask)) {
|
||||
if (playbackState.state == AudioPlayerStarting || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerFinishing) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Song);
|
||||
}
|
||||
}
|
||||
@ -497,9 +489,8 @@ void PlayerWidget::playPausePressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState);
|
||||
if (playing == _song && !(playingState & AudioPlayerStoppedMask)) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == _song && !(playbackState.state & AudioPlayerStoppedMask)) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Song);
|
||||
} else {
|
||||
audioPlayer()->play(_song);
|
||||
@ -581,12 +572,12 @@ void PlayerWidget::step_progress(float64 ms, bool timer) {
|
||||
}
|
||||
|
||||
void PlayerWidget::updateState() {
|
||||
updateState(AudioMsgId(), AudioPlayerStopped, 0, 0, 0);
|
||||
updateState(AudioMsgId(), AudioPlaybackState());
|
||||
}
|
||||
|
||||
void PlayerWidget::updateState(AudioMsgId playing, AudioPlayerState playingState, int64 playingPosition, int64 playingDuration, int32 playingFrequency) {
|
||||
void PlayerWidget::updateState(AudioMsgId playing, AudioPlaybackState playbackState) {
|
||||
if (!playing) {
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
}
|
||||
|
||||
bool songChanged = false;
|
||||
@ -622,20 +613,20 @@ void PlayerWidget::updateState(AudioMsgId playing, AudioPlayerState playingState
|
||||
|
||||
qint64 position = 0, duration = 0, display = 0;
|
||||
if (playing == _song) {
|
||||
if (!(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
display = position = playingPosition;
|
||||
duration = playingDuration;
|
||||
if (!(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
display = position = playbackState.position;
|
||||
duration = playbackState.duration;
|
||||
} else {
|
||||
display = playingDuration;
|
||||
display = playbackState.duration;
|
||||
}
|
||||
display = display / (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);
|
||||
display = display / (playbackState.frequency ? playbackState.frequency : AudioVoiceMsgFrequency);
|
||||
} else if (_song) {
|
||||
display = _song.audio()->song()->duration;
|
||||
}
|
||||
bool showPause = false, stopped = ((playingState & AudioPlayerStoppedMask) || playingState == AudioPlayerFinishing);
|
||||
bool showPause = false, stopped = ((playbackState.state & AudioPlayerStoppedMask) || playbackState.state == AudioPlayerFinishing);
|
||||
bool wasPlaying = (_duration != 0);
|
||||
if (!stopped) {
|
||||
showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting);
|
||||
showPause = (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
|
||||
}
|
||||
QString time;
|
||||
float64 progress = 0.;
|
||||
@ -686,7 +677,7 @@ void PlayerWidget::updateState(AudioMsgId playing, AudioPlayerState playingState
|
||||
_loaded = loaded;
|
||||
}
|
||||
|
||||
if (wasPlaying && playingState == AudioPlayerStoppedAtEnd) {
|
||||
if (wasPlaying && playbackState.state == AudioPlayerStoppedAtEnd) {
|
||||
if (_repeat) {
|
||||
if (_song.audio()) {
|
||||
audioPlayer()->play(_song, OverviewMusicFiles);
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
void step_progress(float64 ms, bool timer);
|
||||
void step_state(uint64 ms, bool timer);
|
||||
|
||||
void updateState(AudioMsgId playing, AudioPlayerState playingState, int64 playingPosition, int64 playingDuration, int32 playingFrequency);
|
||||
void updateState(AudioMsgId playing, AudioPlaybackState playbackState);
|
||||
void updateState();
|
||||
void clearSelection();
|
||||
|
||||
|
@ -953,9 +953,8 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, ActionOnLoad action) {
|
||||
if (!location.isEmpty() || (!data->data().isEmpty() && (playVoice || playMusic || playVideo || playAnimation))) {
|
||||
if (playVoice) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice, &playingState);
|
||||
if (playing == AudioMsgId(data, msgId) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice);
|
||||
if (playing == AudioMsgId(data, msgId) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Voice);
|
||||
} else {
|
||||
AudioMsgId audio(data, msgId);
|
||||
@ -967,9 +966,8 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, ActionOnLoad action) {
|
||||
}
|
||||
} else if (playMusic) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState);
|
||||
if (playing == AudioMsgId(data, msgId) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == AudioMsgId(data, msgId) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Song);
|
||||
} else {
|
||||
AudioMsgId song(data, msgId);
|
||||
@ -1252,9 +1250,8 @@ void DocumentData::performActionOnLoad() {
|
||||
if (playVoice) {
|
||||
if (loaded()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState state = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice, &state);
|
||||
if (playing == AudioMsgId(this, _actionOnLoadMsgId) && !(state & AudioPlayerStoppedMask) && state != AudioPlayerFinishing) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Voice);
|
||||
if (playing == AudioMsgId(this, _actionOnLoadMsgId) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Voice);
|
||||
} else {
|
||||
audioPlayer()->play(AudioMsgId(this, _actionOnLoadMsgId));
|
||||
@ -1264,9 +1261,8 @@ void DocumentData::performActionOnLoad() {
|
||||
} else if (playMusic) {
|
||||
if (loaded()) {
|
||||
AudioMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, AudioMsgId::Type::Song, &playingState);
|
||||
if (playing == AudioMsgId(this, _actionOnLoadMsgId) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song);
|
||||
if (playing == AudioMsgId(this, _actionOnLoadMsgId) && !(playbackState.state & AudioPlayerStoppedMask) && playbackState.state != AudioPlayerFinishing) {
|
||||
audioPlayer()->pauseresume(AudioMsgId::Type::Song);
|
||||
} else {
|
||||
AudioMsgId song(this, _actionOnLoadMsgId);
|
||||
|
Loading…
Reference in New Issue
Block a user