Fix video with autoplay disabled.

This commit is contained in:
John Preston 2019-12-19 13:50:33 +03:00
parent 9f96237b85
commit 4cdf08cbfb
6 changed files with 54 additions and 26 deletions

View File

@ -231,7 +231,7 @@ QSize Gif::videoSize() const {
bool Gif::downloadInCorner() const { bool Gif::downloadInCorner() const {
return _data->isVideoFile() return _data->isVideoFile()
&& !autoplayEnabled() && (_data->loading() || !autoplayEnabled())
&& _data->canBeStreamed() && _data->canBeStreamed()
&& !_data->inappPlaybackFailed() && !_data->inappPlaybackFailed()
&& IsServerMsgId(_parent->data()->id); && IsServerMsgId(_parent->data()->id);
@ -284,7 +284,10 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
? &activeOwnPlaying->instance ? &activeOwnPlaying->instance
: nullptr; : nullptr;
if ((!streamed || item->isSending()) && displayLoading) { if (displayLoading
&& (!streamed
|| item->isSending()
|| (cornerDownload && _data->loading()))) {
ensureAnimation(); ensureAnimation();
if (!_animation->radial.animating()) { if (!_animation->radial.animating()) {
_animation->radial.start(dataProgress()); _animation->radial.start(dataProgress());
@ -416,9 +419,11 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
|| (!streamingMode || (!streamingMode
&& ((!_data->loaded() && !_data->loading()) && ((!_data->loaded() && !_data->loading())
|| !autoplayEnabled()))) { || !autoplayEnabled()))) {
const auto radialOpacity = streamed const auto radialOpacity = item->isSending()
? 1.
: streamed
? streamed->waitingOpacity() ? streamed->waitingOpacity()
: (radial && _data->loaded() && !item->isSending()) : (radial && _data->loaded())
? _animation->radial.opacity() ? _animation->radial.opacity()
: 1.; : 1.;
auto inner = QRect(rthumb.x() + (rthumb.width() - st::msgFileSize) / 2, rthumb.y() + (rthumb.height() - st::msgFileSize) / 2, st::msgFileSize, st::msgFileSize); auto inner = QRect(rthumb.x() + (rthumb.width() - st::msgFileSize) / 2, rthumb.y() + (rthumb.height() - st::msgFileSize) / 2, st::msgFileSize, st::msgFileSize);
@ -441,12 +446,12 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
p.setOpacity(radialOpacity); p.setOpacity(radialOpacity);
const auto icon = [&]() -> const style::icon * { const auto icon = [&]() -> const style::icon * {
if (streamingMode) { if (streamingMode && !_data->uploading()) {
return nullptr; return nullptr;
} else if ((_data->loaded() || canBePlayed) && !radial) { } else if ((_data->loaded() || canBePlayed) && (!radial || cornerDownload)) {
return &(selected ? st::historyFileThumbPlaySelected : st::historyFileThumbPlay); return &(selected ? st::historyFileThumbPlaySelected : st::historyFileThumbPlay);
} else if (radial || _data->loading()) { } else if (radial || _data->loading()) {
if (item->id > 0 || _data->uploading()) { if (!item->isSending() || _data->uploading()) {
return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel); return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel);
} }
return nullptr; return nullptr;
@ -462,7 +467,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
const auto fg = selected const auto fg = selected
? st::historyFileThumbRadialFgSelected ? st::historyFileThumbRadialFgSelected
: st::historyFileThumbRadialFg; : st::historyFileThumbRadialFg;
if (streamed) { if (streamed && !_data->uploading()) {
Ui::InfiniteRadialAnimation::Draw( Ui::InfiniteRadialAnimation::Draw(
p, p,
streamed->waitingState(), streamed->waitingState(),
@ -479,17 +484,6 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
fg); fg);
} }
} }
if (!isRound && (!streamingMode || item->isSending())) {
auto statusX = paintx + st::msgDateImgDelta + st::msgDateImgPadding.x();
auto statusY = painty + st::msgDateImgDelta + st::msgDateImgPadding.y();
auto statusW = st::normalFont->width(_statusText) + 2 * st::msgDateImgPadding.x();
auto statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y();
App::roundRect(p, style::rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners);
p.setFont(st::normalFont);
p.setPen(st::msgDateImgFg);
p.drawTextLeft(statusX, statusY, width(), _statusText, statusW - 2 * st::msgDateImgPadding.x());
}
} }
if (displayMute) { if (displayMute) {
auto muteRect = style::rtlrect(rthumb.x() + (rthumb.width() - st::historyVideoMessageMuteSize) / 2, rthumb.y() + st::msgDateImgDelta, st::historyVideoMessageMuteSize, st::historyVideoMessageMuteSize, width()); auto muteRect = style::rtlrect(rthumb.x() + (rthumb.width() - st::historyVideoMessageMuteSize) / 2, rthumb.y() + st::msgDateImgDelta, st::historyVideoMessageMuteSize, st::historyVideoMessageMuteSize, width());
@ -615,8 +609,8 @@ void Gif::drawCornerStatus(Painter &p, bool selected) const {
: _statusText; : _statusText;
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 cornerMute = _streamed && _data->isVideoFile() && !cornerDownload;
const auto addLeft = 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 addRight = cornerMute ? st::historyVideoMuteSize : 0;
const auto downloadWidth = cornerDownload ? st::normalFont->width(_downloadSize) : 0; const auto downloadWidth = cornerDownload ? st::normalFont->width(_downloadSize) : 0;
@ -1067,7 +1061,7 @@ void Gif::updateStatusText() const {
statusSize = FileStatusSizeFailed; statusSize = FileStatusSizeFailed;
} else if (_data->uploading()) { } else if (_data->uploading()) {
statusSize = _data->uploadingData->offset; statusSize = _data->uploadingData->offset;
} else if (_data->loading()) { } else if (!downloadInCorner() && _data->loading()) {
statusSize = _data->loadOffset(); statusSize = _data->loadOffset();
} else if (_data->loaded() || _data->canBePlayed()) { } else if (_data->loaded() || _data->canBePlayed()) {
statusSize = FileStatusSizeLoaded; statusSize = FileStatusSizeLoaded;

View File

@ -467,6 +467,11 @@ void Player::provideStartInformation() {
} else { } else {
_stage = Stage::Ready; _stage = Stage::Ready;
if (_audio && _audioFinished) {
// Audio was stopped before it was ready.
_audio->stop();
}
// Don't keep the reference to the video cover. // Don't keep the reference to the video cover.
auto copy = _information; auto copy = _information;
_information.video.cover = QImage(); _information.video.cover = QImage();
@ -583,8 +588,11 @@ void Player::stopAudio() {
stop(); stop();
} else if (_audio) { } else if (_audio) {
_audioFinished = true; _audioFinished = true;
if (_information.audio.state.duration != kTimeUnknown) {
// Audio is ready.
_audio->stop(); _audio->stop();
} }
}
} }
void Player::updatePausedState() { void Player::updatePausedState() {
@ -803,6 +811,15 @@ void Player::setSpeed(float64 speed) {
} }
} }
void Player::setWaitForMarkAsShown(bool wait) {
if (_options.waitForMarkAsShown != wait) {
_options.waitForMarkAsShown = wait;
if (_video) {
_video->setWaitForMarkAsShown(wait);
}
}
}
bool Player::active() const { bool Player::active() const {
return (_stage != Stage::Uninitialized) && !finished() && !failed(); return (_stage != Stage::Uninitialized) && !finished() && !failed();
} }
@ -906,6 +923,10 @@ void Player::unlock() {
Expects(_locks > 0); Expects(_locks > 0);
--_locks; --_locks;
if (!_locks) {
stopAudio();
setWaitForMarkAsShown(true);
}
} }
bool Player::locked() const { bool Player::locked() const {

View File

@ -53,6 +53,7 @@ public:
[[nodiscard]] float64 speed() const; [[nodiscard]] float64 speed() const;
void setSpeed(float64 speed); // 0.5 <= speed <= 2. void setSpeed(float64 speed); // 0.5 <= speed <= 2.
void setWaitForMarkAsShown(bool wait);
[[nodiscard]] bool playing() const; [[nodiscard]] bool playing() const;
[[nodiscard]] bool buffering() const; [[nodiscard]] bool buffering() const;

View File

@ -42,6 +42,7 @@ public:
void pause(crl::time time); void pause(crl::time time);
void resume(crl::time time); void resume(crl::time time);
void setSpeed(float64 speed); void setSpeed(float64 speed);
void setWaitForMarkAsShown(bool wait);
void interrupt(); void interrupt();
void frameShown(); void frameShown();
void addTimelineDelay(crl::time delayed); void addTimelineDelay(crl::time delayed);
@ -417,6 +418,13 @@ void VideoTrackObject::setSpeed(float64 speed) {
_options.speed = speed; _options.speed = speed;
} }
void VideoTrackObject::setWaitForMarkAsShown(bool wait) {
if (interrupted()) {
return;
}
_options.waitForMarkAsShown = wait;
}
bool VideoTrackObject::interrupted() const { bool VideoTrackObject::interrupted() const {
return (_shared == nullptr); return (_shared == nullptr);
} }
@ -908,6 +916,12 @@ void VideoTrack::setSpeed(float64 speed) {
}); });
} }
void VideoTrack::setWaitForMarkAsShown(bool wait) {
_wrapped.with([=](Implementation &unwrapped) {
unwrapped.setWaitForMarkAsShown(wait);
});
}
crl::time VideoTrack::nextFrameDisplayTime() const { crl::time VideoTrack::nextFrameDisplayTime() const {
return _shared->nextFrameDisplayTime(); return _shared->nextFrameDisplayTime();
} }

View File

@ -47,6 +47,7 @@ public:
// Called from the main thread. // Called from the main thread.
void setSpeed(float64 speed); void setSpeed(float64 speed);
void setWaitForMarkAsShown(bool wait);
// Called from the main thread. // Called from the main thread.
// Returns the position of the displayed frame. // Returns the position of the displayed frame.

View File

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