Show inline video playback state.

This commit is contained in:
John Preston 2019-12-17 16:04:53 +03:00
parent 9b9ea336be
commit 51dac66998
4 changed files with 50 additions and 24 deletions

View File

@ -586,6 +586,7 @@ historyGroupAboutTextSkip: 10px;
historyGroupAboutSkip: 8px; historyGroupAboutSkip: 8px;
historyVideoDownloadSize: msgFileSize; historyVideoDownloadSize: msgFileSize;
historyVideoMuteSize: 22px;
historyVideoCancel: icon {{ "playlist_cancel", historyFileThumbIconFg }}; historyVideoCancel: icon {{ "playlist_cancel", historyFileThumbIconFg }};
historyVideoCancelSelected: icon {{ "playlist_cancel", historyFileThumbIconFgSelected }}; historyVideoCancelSelected: icon {{ "playlist_cancel", historyFileThumbIconFgSelected }};
historyVideoDownload: icon {{ "playlist_download", historyFileThumbIconFg }}; historyVideoDownload: icon {{ "playlist_download", historyFileThumbIconFg }};

View File

@ -62,7 +62,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
constexpr auto kScrollDateHideTimeout = 1000; constexpr auto kScrollDateHideTimeout = 1000;
constexpr auto kUnloadHeavyPartsPages = 3; constexpr auto kUnloadHeavyPartsPages = 1;
// Helper binary search for an item in a list that is not completely // Helper binary search for an item in a list that is not completely
// above the given top of the visible area or below the given bottom of the visible area // above the given top of the visible area or below the given bottom of the visible area

View File

@ -233,6 +233,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
//auto loaded = _data->loaded(); //auto loaded = _data->loaded();
auto displayLoading = (item->id < 0) || _data->displayLoading(); auto displayLoading = (item->id < 0) || _data->displayLoading();
auto selected = (selection == FullSelection); auto selected = (selection == FullSelection);
const auto autoPaused = App::wnd()->sessionController()->isGifPausedAtLeastFor(Window::GifPauseReason::Any);
const auto cornerDownload = downloadInCorner(); const auto cornerDownload = downloadInCorner();
const auto canBePlayed = _data->canBePlayed(); const auto canBePlayed = _data->canBePlayed();
const auto activeRoundPlaying = activeRoundStreamed(); const auto activeRoundPlaying = activeRoundStreamed();
@ -242,7 +243,9 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
&& !_streamed && !_streamed
&& !activeRoundPlaying; && !activeRoundPlaying;
if (startPlayAsync) { if (startPlayAsync) {
_parent->delegate()->elementAnimationAutoplayAsync(_parent); if (!autoPaused) {
_parent->delegate()->elementAnimationAutoplayAsync(_parent);
}
} else if (_streamed && !_streamed->active() && !_streamed->failed()) { } else if (_streamed && !_streamed->active() && !_streamed->failed()) {
startStreamedPlayer(); startStreamedPlayer();
} }
@ -298,7 +301,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
auto roundCorners = (isRound || inWebPage) ? RectPart::AllCorners : ((isBubbleTop() ? (RectPart::TopLeft | RectPart::TopRight) : RectPart::None) auto roundCorners = (isRound || inWebPage) ? RectPart::AllCorners : ((isBubbleTop() ? (RectPart::TopLeft | RectPart::TopRight) : RectPart::None)
| ((isBubbleBottom() && _caption.isEmpty()) ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None)); | ((isBubbleBottom() && _caption.isEmpty()) ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None));
if (streamed) { if (streamed) {
auto paused = App::wnd()->sessionController()->isGifPausedAtLeastFor(Window::GifPauseReason::Any); auto paused = autoPaused;
if (isRound) { if (isRound) {
if (activeRoundStreamed()) { if (activeRoundStreamed()) {
paused = false; paused = false;
@ -458,7 +461,9 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
(selected ? st::historyVideoMessageMuteSelected : st::historyVideoMessageMute).paintInCenter(p, muteRect); (selected ? st::historyVideoMessageMuteSelected : st::historyVideoMessageMute).paintInCenter(p, muteRect);
} }
drawCornerStatus(p, selected); if (!isRound) {
drawCornerStatus(p, selected);
}
if (!inWebPage && isRound) { if (!inWebPage && isRound) {
auto mediaUnread = item->hasUnreadMediaFlag(); auto mediaUnread = item->hasUnreadMediaFlag();
@ -546,8 +551,8 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
fullRight = maxRight; fullRight = maxRight;
} }
} }
if (isRound || needInfoDisplay()) { if (isRound) {
_parent->drawInfo(p, fullRight, fullBottom, 2 * paintx + paintw, selected, isRound ? InfoDisplayType::Background : InfoDisplayType::Image); _parent->drawInfo(p, fullRight, fullBottom, 2 * paintx + paintw, selected, InfoDisplayType::Background);
} }
if (!bubble && _parent->displayRightAction()) { if (!bubble && _parent->displayRightAction()) {
auto fastShareLeft = (fullRight + st::historyFastShareLeft); auto fastShareLeft = (fullRight + st::historyFastShareLeft);
@ -562,12 +567,17 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
} }
void Gif::drawCornerStatus(Painter &p, bool selected) const { void Gif::drawCornerStatus(Painter &p, bool selected) const {
if (!needInfoDisplay()) {
return;
}
const auto padding = st::msgDateImgPadding; const auto padding = st::msgDateImgPadding;
const auto radial = _animation && _animation->radial.animating(); const auto radial = _animation && _animation->radial.animating();
const auto cornerMute = _streamed && _data->isVideoFile();
const auto cornerDownload = downloadInCorner() && !_data->loaded() && !_data->loadedInMediaCache(); const auto cornerDownload = downloadInCorner() && !_data->loaded() && !_data->loadedInMediaCache();
const auto addWidth = cornerDownload ? (st::historyVideoDownloadSize + 2 * padding.y()) : 0; const auto addLeft = cornerDownload ? (st::historyVideoDownloadSize + 2 * padding.y()) : 0;
const auto addRight = cornerMute ? st::historyVideoMuteSize : 0;
const auto downloadWidth = cornerDownload ? st::normalFont->width(_downloadSize) : 0; const auto downloadWidth = cornerDownload ? st::normalFont->width(_downloadSize) : 0;
const auto statusW = std::max(downloadWidth, st::normalFont->width(_statusText)) + 2 * padding.x() + addWidth; const auto statusW = std::max(downloadWidth, st::normalFont->width(_statusText)) + 2 * padding.x() + addLeft + addRight;
const auto statusH = cornerDownload ? (st::historyVideoDownloadSize + 2 * padding.y()) : (st::normalFont->height + 2 * padding.y()); const auto statusH = cornerDownload ? (st::historyVideoDownloadSize + 2 * padding.y()) : (st::normalFont->height + 2 * padding.y());
const auto statusX = st::msgDateImgDelta + padding.x(); const auto statusX = st::msgDateImgDelta + padding.x();
const auto statusY = st::msgDateImgDelta + padding.y(); const auto statusY = st::msgDateImgDelta + padding.y();
@ -576,10 +586,10 @@ void Gif::drawCornerStatus(Painter &p, bool selected) const {
App::roundRect(p, around, selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); App::roundRect(p, around, selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners);
p.setFont(st::normalFont); p.setFont(st::normalFont);
p.setPen(st::msgDateImgFg); p.setPen(st::msgDateImgFg);
p.drawTextLeft(statusX + addWidth, statusTextTop, width(), _statusText, statusW - 2 * padding.x()); p.drawTextLeft(statusX + addLeft, statusTextTop, width(), _statusText, statusW - 2 * padding.x());
if (cornerDownload) { if (cornerDownload) {
const auto downloadTextTop = statusY + st::normalFont->height + (2 * (statusH - 2 * st::normalFont->height) / 3) - padding.y(); const auto downloadTextTop = statusY + st::normalFont->height + (2 * (statusH - 2 * st::normalFont->height) / 3) - padding.y();
p.drawTextLeft(statusX + addWidth, downloadTextTop, width(), _downloadSize, statusW - 2 * padding.x()); p.drawTextLeft(statusX + addLeft, downloadTextTop, width(), _downloadSize, statusW - 2 * padding.x());
const auto inner = QRect(statusX + padding.y() - padding.x(), statusY, st::historyVideoDownloadSize, st::historyVideoDownloadSize); const auto inner = QRect(statusX + padding.y() - padding.x(), statusY, st::historyVideoDownloadSize, st::historyVideoDownloadSize);
const auto icon = [&]() -> const style::icon * { const auto icon = [&]() -> const style::icon * {
if (_data->loading()) { if (_data->loading()) {
@ -594,6 +604,8 @@ void Gif::drawCornerStatus(Painter &p, bool selected) const {
QRect rinner(inner.marginsRemoved(QMargins(st::historyVideoRadialLine, st::historyVideoRadialLine, st::historyVideoRadialLine, st::historyVideoRadialLine))); QRect rinner(inner.marginsRemoved(QMargins(st::historyVideoRadialLine, st::historyVideoRadialLine, st::historyVideoRadialLine, st::historyVideoRadialLine)));
_animation->radial.draw(p, rinner, st::historyVideoRadialLine, selected ? st::historyFileThumbRadialFgSelected : st::historyFileThumbRadialFg); _animation->radial.draw(p, rinner, st::historyVideoRadialLine, selected ? st::historyFileThumbRadialFgSelected : st::historyFileThumbRadialFg);
} }
} else if (cornerMute) {
(selected ? st::historyVideoMessageMuteSelected : st::historyVideoMessageMute).paint(p, statusX - padding.x() - padding.y() + statusW - addRight, statusY - padding.y() + (statusH - st::historyVideoMessageMute.height()) / 2, width());
} }
} }
@ -601,7 +613,7 @@ TextState Gif::cornerStatusTextState(
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
if (!downloadInCorner() || _data->loaded()) { if (!needInfoDisplay() || !downloadInCorner() || _data->loaded()) {
return result; return result;
} }
const auto padding = st::msgDateImgPadding; const auto padding = st::msgDateImgPadding;
@ -712,8 +724,10 @@ TextState Gif::textState(QPoint point, StateRequest request) const {
} }
} }
} }
if (const auto state = cornerStatusTextState(point, request); state.link) { if (!isRound) {
return state; if (const auto state = cornerStatusTextState(point, request); state.link) {
return state;
}
} }
if (QRect(usex + paintx, painty, usew, painth).contains(point)) { if (QRect(usex + paintx, painty, usew, painth).contains(point)) {
if (_data->uploading()) { if (_data->uploading()) {
@ -987,15 +1001,18 @@ void Gif::validateGroupedCache(
} }
void Gif::setStatusSize(int newSize) const { void Gif::setStatusSize(int newSize) const {
if (_data->isVideoMessage()) { if (newSize < 0) {
_statusSize = newSize; _statusSize = newSize;
if (newSize < 0) { _statusText = formatDurationText(-newSize - 1);
_statusText = formatDurationText(-newSize - 1); } else if (_data->isVideoMessage()) {
} else { _statusSize = newSize;
_statusText = formatDurationText(_data->getDuration()); _statusText = formatDurationText(_data->getDuration());
}
} else { } else {
File::setStatusSize(newSize, _data->size, -2, 0); File::setStatusSize(
newSize,
_data->size,
_data->isVideoFile() ? _data->getDuration() : -2,
0);
} }
} }
@ -1009,12 +1026,15 @@ void Gif::updateStatusText() const {
statusSize = _data->uploadingData->offset; statusSize = _data->uploadingData->offset;
} else if (_data->loading()) { } else if (_data->loading()) {
statusSize = _data->loadOffset(); statusSize = _data->loadOffset();
} else if (_data->loaded()) { } else if (_data->loaded() || _data->canBePlayed()) {
statusSize = FileStatusSizeLoaded; statusSize = FileStatusSizeLoaded;
} else { } else {
statusSize = FileStatusSizeReady; statusSize = FileStatusSizeReady;
} }
if (const auto streamed = activeRoundStreamed()) { const auto round = activeRoundStreamed();
const auto own = activeOwnStreamed();
if (round || (own && _data->isVideoFile())) {
const auto streamed = round ? round : own;
const auto state = streamed->player().prepareLegacyState(); const auto state = streamed->player().prepareLegacyState();
if (state.length) { if (state.length) {
auto position = int64(0); auto position = int64(0);
@ -1237,7 +1257,9 @@ bool Gif::dataLoaded() const {
} }
bool Gif::needInfoDisplay() const { bool Gif::needInfoDisplay() const {
return (_parent->data()->id < 0 || _parent->isUnderCursor()); return _data->isVideoFile()
|| _parent->data()->isSending()
|| _parent->isUnderCursor();
} }
} // namespace HistoryView } // namespace HistoryView

View File

@ -434,7 +434,10 @@ bool OverlayWidget::documentBubbleShown() const {
void OverlayWidget::clearStreaming() { void OverlayWidget::clearStreaming() {
_fullScreenVideo = false; _fullScreenVideo = false;
_streamed = nullptr; if (_streamed) {
_streamed->instance.stop();
_streamed = nullptr;
}
} }
void OverlayWidget::documentUpdated(DocumentData *doc) { void OverlayWidget::documentUpdated(DocumentData *doc) {