~aleteoryx/muditaos

86ea73eb78e5300539b89e304817c6d2a6bb8299 — tomaszkrosnowski 4 years ago a053277
[EGD-7861] Fixed MP track change flow

When next/prev track was played the screen was blinking with stopped
state for a short moment between last track is finished and before
current track is started.
M module-apps/application-music-player/presenters/SongsPresenter.cpp => module-apps/application-music-player/presenters/SongsPresenter.cpp +11 -4
@@ 35,11 35,14 @@ namespace app::music_player

    bool SongsPresenter::play(const std::string &filePath)
    {
        waitingToPlay = true;
        return audioOperations->play(filePath, [this, filePath](audio::RetCode retCode, audio::Token token) {
            waitingToPlay = false;
            if (retCode != audio::RetCode::Success || !token.IsValid()) {
                LOG_ERROR("Playback audio operation failed, retcode = %s, token validity = %d",
                          str(retCode).c_str(),
                          token.IsValid());
                refreshView();
                return;
            }



@@ 170,8 173,10 @@ namespace app::music_player
            if (changePlayingStateCallback != nullptr) {
                changePlayingStateCallback(SongState::NotPlaying);
            }
            updateViewSongState();
            refreshView();
            if (!waitingToPlay) {
                updateViewSongState();
                refreshView();
            }
            return true;
        }
        return false;


@@ 186,12 191,14 @@ namespace app::music_player
            if (changePlayingStateCallback != nullptr) {
                changePlayingStateCallback(SongState::NotPlaying);
            }
            updateViewSongState();
            refreshView();
            auto nextSongToPlay = songsModelInterface->getNextFilePath(currentSongContext.filePath);
            if (!nextSongToPlay.empty()) {
                requestAudioOperation(nextSongToPlay);
            }
            else {
                updateViewSongState();
                refreshView();
            }
            return true;
        }
        return false;

M module-apps/application-music-player/presenters/SongsPresenter.hpp => module-apps/application-music-player/presenters/SongsPresenter.hpp +1 -0
@@ 108,5 108,6 @@ namespace app::music_player
        std::chrono::time_point<std::chrono::system_clock> songProgressTimestamp;
        std::chrono::milliseconds songMillisecondsElapsed{0};
        float currentProgressRatio = 0.0;
        bool waitingToPlay         = false;
    };
} // namespace app::music_player

M module-apps/application-music-player/windows/MusicPlayerMainWindow.cpp => module-apps/application-music-player/windows/MusicPlayerMainWindow.cpp +21 -16
@@ 518,22 518,27 @@ namespace gui
            }
        }

        snprintf(timeToDisplay,
                 maxTimeToDisplaySize,
                 "%d:%02d:%02d",
                 static_cast<int>(currentTotalTime) / utils::time::secondsInHour,
                 static_cast<int>((currentTotalTime) % utils::time::secondsInHour) / 60,
                 static_cast<int>(currentTotalTime) % utils::time::secondsInMinute);
        currentTotalTimeString = timeToDisplay;

        auto elapsedTime = static_cast<uint32_t>(currentTotalTime * currentProgress);
        snprintf(timeToDisplay,
                 maxTimeToDisplaySize,
                 "%d:%02d:%02d",
                 static_cast<int>(elapsedTime) / utils::time::secondsInHour,
                 static_cast<int>((elapsedTime) % utils::time::secondsInHour) / 60,
                 static_cast<int>(elapsedTime) % utils::time::secondsInMinute);
        currentTimeString = timeToDisplay;
        auto secsToStr = [&](int secs) {
            if (secs < 3600) {
                snprintf(timeToDisplay,
                         maxTimeToDisplaySize,
                         "%d:%02d",
                         static_cast<int>(secs / utils::time::secondsInMinute),
                         static_cast<int>(secs) % utils::time::secondsInMinute);
            }
            else {
                snprintf(timeToDisplay,
                         maxTimeToDisplaySize,
                         "%d:%02d:%02d",
                         static_cast<int>(secs) / utils::time::secondsInHour,
                         static_cast<int>((secs) % utils::time::secondsInHour) / utils::time::secondsInMinute,
                         static_cast<int>(secs) % utils::time::secondsInMinute);
            }
            return timeToDisplay;
        };

        currentTotalTimeString = secsToStr(currentTotalTime);
        currentTimeString      = secsToStr(static_cast<uint32_t>(currentTotalTime * currentProgress));

        if (totalTimeText != nullptr)
            totalTimeText->setRichText(currentTotalTimeString);