fix: correctly display duration statistic in preview panel#1421
Open
ludvig-sandh wants to merge 3 commits into
Open
fix: correctly display duration statistic in preview panel#1421ludvig-sandh wants to merge 3 commits into
ludvig-sandh wants to merge 3 commits into
Conversation
3 tasks
CyanVoxel
reviewed
Jul 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1037, where previewing a video/audio didn't display the duration until selected again. Once selected again, duration was displayed, but a million times larger than expected.
The "million times larger" problem came from multiplying the duration in milliseconds by 1000. The fix was to divide by 1000 instead, to get seconds.
The problem of the duration not showing up was due to QMediaPlayer loading the duration asynchronously but the UI's trying to access it immediately. I fixed it by adding a signal that is triggered when the duration is available by QMediaPlayer. This signal causes the UI to update again via a callback, this time including the duration.
Some extra details:
dur_str = str(timedelta(seconds=float(stats.duration)))[:-7]I think the idea was to strip out the microseconds (6 digits plus the decimal point). However, converting a timedelta to a string doesn't include microseconds. So this solution incorrectly pruned 7 characters from the valid duration string. I ended up replacing it with my own formatter for clarity.
Tasks Completed
Evidence of correct duration stats:

Also tried quickly selecting different files and verified that always the expected duration showed up on screen.