diff --git a/Telegram/SourceFiles/media/stories/media_stories_sibling.cpp b/Telegram/SourceFiles/media/stories/media_stories_sibling.cpp index ac3c432589..90a3939542 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_sibling.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_sibling.cpp @@ -75,6 +75,7 @@ public: private: void waitForGoodThumbnail(); bool updateAfterGoodCheck(); + void createStreamedPlayer(); void streamedFailed(); const not_null _video; @@ -148,38 +149,49 @@ QImage Sibling::LoaderVideo::blurred() { QImage Sibling::LoaderVideo::good() { if (const auto image = _media->goodThumbnail()) { return image->original(); - } else if (!_video->goodThumbnailChecked()) { + } else if (!_video->goodThumbnailChecked() + && !_video->goodThumbnailNoData()) { if (!_checkingGoodInCache) { waitForGoodThumbnail(); } } else if (_failed) { return QImage(); } else if (!_streamed) { - _streamed = std::make_unique( - _video, - _origin, - [] {}); // waitingCallback - _streamed->lockPlayer(); - _streamed->player().updates( - ) | rpl::start_with_next_error([=](Streaming::Update &&update) { - v::match(update.data, [&](Streaming::Information &update) { - _update(); - }, [](const auto &update) { - }); - }, [=](Streaming::Error &&error) { - streamedFailed(); - }, _streamed->lifetime()); - if (_streamed->ready()) { - _update(); - } else if (!_streamed->valid()) { - streamedFailed(); - } + createStreamedPlayer(); } else if (_streamed->ready()) { return _streamed->info().video.cover; } return QImage(); } +void Sibling::LoaderVideo::createStreamedPlayer() { + _streamed = std::make_unique( + _video, + _origin, + [] {}); // waitingCallback + _streamed->lockPlayer(); + _streamed->player().updates( + ) | rpl::start_with_next_error([=](Streaming::Update &&update) { + v::match(update.data, [&](Streaming::Information &update) { + _update(); + }, [](const auto &update) { + }); + }, [=](Streaming::Error &&error) { + streamedFailed(); + }, _streamed->lifetime()); + if (_streamed->ready()) { + _update(); + } else if (!_streamed->valid()) { + streamedFailed(); + } else if (!_streamed->player().active() + && !_streamed->player().finished()) { + _streamed->play({ + .mode = Streaming::Mode::Video, + }); + _streamed->pause(); + } +} + void Sibling::LoaderVideo::streamedFailed() { _failed = true; _streamed = nullptr; @@ -204,7 +216,8 @@ void Sibling::LoaderVideo::waitForGoodThumbnail() { } bool Sibling::LoaderVideo::updateAfterGoodCheck() { - if (!_video->goodThumbnailChecked()) { + if (!_video->goodThumbnailChecked() + && !_video->goodThumbnailNoData()) { return false; } _checkingGoodInCache = false; diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_document.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_document.cpp index 039b76261f..27c090443d 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_document.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_document.cpp @@ -257,12 +257,15 @@ void Document::validateGoodThumbnail() { const auto length = bytes.size(); if (!length || length > Storage::kMaxFileInMemory) { LOG(("App Error: Bad thumbnail data for saving to cache.")); - bytes = "(failed)"; + bytes = "(failed)"_q; } crl::on_main(guard, [=] { if (const auto active = document->activeMediaView()) { active->setGoodThumbnail(image); } + if (bytes != "(failed)"_q) { + document->setGoodThumbnailChecked(true); + } document->owner().cache().putIfEmpty( document->goodThumbnailCacheKey(), Storage::Cache::Database::TaggedValue(