From 4f7f569ddde6bd44b4d3c61002551948e81bb65a Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 13 Jul 2015 20:56:44 +0300 Subject: [PATCH] fixed double play of audio after download complete --- Telegram/SourceFiles/audio.cpp | 30 ++++++++++++++++++++++++++++- Telegram/SourceFiles/mainwidget.cpp | 5 ++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/audio.cpp b/Telegram/SourceFiles/audio.cpp index 79978f250..831b41f88 100644 --- a/Telegram/SourceFiles/audio.cpp +++ b/Telegram/SourceFiles/audio.cpp @@ -1341,6 +1341,15 @@ void AudioPlayerLoaders::onStart(const AudioMsgId &audio, qint64 position) { _audio = AudioMsgId(); delete _audioLoader; _audioLoader = 0; + + { + QMutexLocker lock(&playerMutex); + AudioPlayer *voice = audioPlayer(); + if (!voice) return; + + voice->_audioData[voice->_audioCurrent].loading = true; + } + loadData(OverviewAudios, static_cast(&audio), position); } @@ -1348,6 +1357,15 @@ void AudioPlayerLoaders::onStart(const SongMsgId &song, qint64 position) { _song = SongMsgId(); delete _songLoader; _songLoader = 0; + + { + QMutexLocker lock(&playerMutex); + AudioPlayer *voice = audioPlayer(); + if (!voice) return; + + voice->_songData[voice->_songCurrent].loading = true; + } + loadData(OverviewDocuments, static_cast(&song), position); } @@ -1404,15 +1422,25 @@ void AudioPlayerLoaders::loadData(MediaOverviewType type, const void *objId, qin return; } - bool started = (err == SetupNoErrorStarted), finished = false; + bool started = (err == SetupNoErrorStarted), finished = false, errAtStart = started; QByteArray result; int64 samplesAdded = 0, frequency = l->frequency(), format = l->format(); while (result.size() < AudioVoiceMsgBufferSize) { if (!l->readMore(result, samplesAdded)) { + if (errAtStart) { + { + QMutexLocker lock(&playerMutex); + AudioPlayer::Msg *m = checkLoader(type); + if (m) m->state = AudioPlayerStoppedAtStart; + } + emitError(type); + return; + } finished = true; break; } + errAtStart = false; QMutexLocker lock(&playerMutex); if (!checkLoader(type)) { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 9a0d72fec..4ee53656a 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1575,6 +1575,7 @@ void MainWidget::audioLoadRetry() { } void MainWidget::documentLoadProgress(mtpFileLoader *loader) { + bool songPlayActivated = false; DocumentData *document = App::document(loader->objId()); if (document->loader) { if (document->loader->done()) { @@ -1595,6 +1596,8 @@ void MainWidget::documentLoadProgress(mtpFileLoader *loader) { audioPlayer()->play(song); if (App::main()) App::main()->documentPlayProgress(song); } + + songPlayActivated = true; } else if(document->openOnSave > 0 && document->size < MediaViewImageSizeLimit) { QImageReader reader(already); if (reader.canRead()) { @@ -1628,7 +1631,7 @@ void MainWidget::documentLoadProgress(mtpFileLoader *loader) { } App::wnd()->documentUpdated(document); - if (audioPlayer()) { + if (!songPlayActivated && audioPlayer()) { SongMsgId playing; AudioPlayerState playingState = AudioPlayerStopped; int64 playingPosition = 0, playingDuration = 0;