Skip to content

Keep an autoplaying video from jumping back to the start - #31657

Open
oviron wants to merge 4 commits into
telegramdesktop:devfrom
oviron:tdesktop-inline-video-restart
Open

oviron wants to merge 4 commits into
telegramdesktop:devfrom
oviron:tdesktop-inline-video-restart

Conversation

@oviron

@oviron oviron commented Nov 19, 2026 •

Copy link
Copy Markdown

An autoplaying video in a chat or channel can play for a few seconds, jump back to the first frame and start over. It happens to videos with alternative qualities, and two places lose the position. Two more commits cover what is left around the switch.

Quality switch. The inline player starts with the quality from the settings, 480p by default. When the speed estimate allows a larger rendition and four seconds are preloaded, Streaming::Document requests it, and Gif::createStreamedPlayer() replaces the stream. startStreamedPlayer() then takes the position from the message timestamp or the saved position of the document, which is zero for a video that was never opened in the viewer. The first estimate comes no earlier than five seconds after the first request, so the jump comes a few seconds into the video. A switch down while the video waits for data loses the position the same way. The media viewer and PiP already pass the current position when they switch (OverlayWidget::applyVideoQuality(), Pip::applyVideoQuality()).

The first commit remembers the position of the replaced stream and starts the new one from it. It reads the position from the Streaming::Document information, which is updated on the main thread and already holds the start position while the player is initializing. The position is used once, so a first start and a later restart of the same stream behave as before.

View rebuild. Gif::~Gif() keeps the stream alive for five seconds so that a recreated view picks up the running player. It asks Data::Streaming to keep the original document, but the stream is registered under the chosen rendition. When a rendition plays, nothing is kept, and the new view starts a new player from the start. Editing the post is enough: applyEdition() recreates the media, and finishEdition() requests a new view.

The second commit keeps alive the document that is streamed.

A playing video and a quality chosen elsewhere. The handler of switchQualityRequests returned when the saved quality already had the requested height. That is the case when another video, the media viewer or PiP switched first: this video asks for the same height later, finds it saved and keeps its lower rendition, while every video started after that plays the higher one. The third commit returns there only if the cell already plays what the setting selects.

It also takes the replacement out of the handler. The handler runs inside the player's own update, so replacing the stream there can destroy that player, and two views of one video in different renditions can call each other's handlers without end through Data::Streaming::sharedDocument() and Document::setOtherQualities(). Now the handler only saves the height, and the replacement runs from the event loop if the stream is still the same.

A switch that cannot start. If the new stream fails before it is ready, for example on the seek to the carried position, the cell kept the failed stream and showed a still frame: checkStreamedIsStarted() does not start a failed one. The fourth commit drops such a stream, and the video starts again by the usual rules. Streaming::Document has marked a rendition that failed to open by then, so another one is chosen; if the original itself failed to open, the video stays unplayable as before.

Not covered: a rebuilt view still starts over if the quality setting changed in between, because another video switched it and the new view then chooses a different rendition. While a new rendition opens, the cover is shown for a moment, as before.

Our fork of AyuGram, which tracks Telegram Desktop 7.4.4, ships these commits in AyuGram 7.4.4-3 (universal macOS and Windows x64, built by CI). The macOS build starts and runs; the behaviour itself has not been checked by observation yet.

This pull request was prepared with the help of an AI assistant (Claude Code).

🤖 Generated with Claude Code

@oviron
oviron force-pushed the tdesktop-inline-video-restart branch from 074f6fd to c452d60 Compare November 19, 2026 12:40
@oviron

oviron commented Nov 19, 2026

Copy link
Copy Markdown
Author

Update: the branch has two more commits, both described above, and its first commit was fixed. It named kTimeUnknown in the wrong namespace and would not have compiled.

Our fork ships all four commits in AyuGram 7.4.4-3, universal macOS and Windows x64, built by CI. The macOS build starts and runs; I have not yet checked the behaviour itself by observation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant