Skip to content

fix: correctly display duration statistic in preview panel#1421

Open
ludvig-sandh wants to merge 3 commits into
TagStudioDev:mainfrom
ludvig-sandh:fix-thumb-panel-duration
Open

fix: correctly display duration statistic in preview panel#1421
ludvig-sandh wants to merge 3 commits into
TagStudioDev:mainfrom
ludvig-sandh:fix-thumb-panel-duration

Conversation

@ludvig-sandh

Copy link
Copy Markdown
Contributor

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:

  • I return early in the callback if the selected preview file has been changed by the user. This avoids displaying stale preview information.
  • The function updating the preview stats (in the UI) is called both immediately and upon the callback, making sure the immediately available data still shows up on screen even if QMediaPlayer would be slow/fail to load the duration.
  • Renamed PreviewThumbView.__filepath to PreviewThumbView.__thumb_filepath since we now store both the path to the thumb and media file in that class, and we want to distinguish them. Just makes everything clearer.
  • Previously this solution was used for formatting the duration:
    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:
image

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

  • Platforms Tested:
    • Windows x86
    • Windows ARM
    • macOS x86
    • macOS ARM
    • Linux x86
    • Linux ARM
  • Tested For:
    • Basic functionality
    • PyInstaller executable

@CyanVoxel CyanVoxel added Type: UI/UX User interface and/or user experience Priority: Medium An issue that shouldn't be be saved for last Status: Review Needed A review of this is needed Type: Fix A fix for a bug, typo, or other issue labels Jul 4, 2026
@CyanVoxel CyanVoxel moved this to 🏓 Ready for Review in TagStudio Development Jul 4, 2026
Comment thread src/tagstudio/qt/views/preview_thumb_view.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Medium An issue that shouldn't be be saved for last Status: Review Needed A review of this is needed Type: Fix A fix for a bug, typo, or other issue Type: UI/UX User interface and/or user experience

Projects

Status: 🏓 Ready for Review

Development

Successfully merging this pull request may close these issues.

[Bug]: File Duration Label Non-Functional

2 participants