v0.1.3: start time honored when replaying the already-loaded track

QMediaPlayer.setSource() no-ops on an unchanged URL, so replaying the
track that was already the loaded source never re-fired LoadedMedia and
the armed _pending_start_ms was silently dropped — a freshly edited
start time appeared to save but playback began at 0:00. _load_current
now detects the unchanged source and stop()+seeks directly (a forced
clear+reload was tried and races the FFmpeg backend, snapping the seek
back to 0). previous()-restart likewise rewinds to the custom start
time instead of 0:00.

Verified live via an offscreen GUI harness: replay-while-playing,
replay-after-EndOfMedia, and cleared-start-time replay.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-05 06:28:21 -04:00
co-authored by Claude Fable 5
parent f94a66963b
commit a50c39fa43
4 changed files with 159 additions and 3 deletions
+16 -2
View File
@@ -239,7 +239,10 @@ class Player(QObject):
return
prev_index = self._step_index(-1)
if self._media.position() > RESTART_THRESHOLD_MS or prev_index is None:
self._media.setPosition(0)
# "Restart" means the track's custom start time, not 0:00.
start = (self._current_track.start_time
if self._current_track else 0)
self._media.setPosition(max(0, start))
else:
self._index = prev_index
self._load_current(autoplay=self.is_playing())
@@ -293,7 +296,18 @@ class Player(QObject):
else:
self._stop_at_ms = 0
self._counted_finish_id = None
self._media.setSource(QUrl.fromLocalFile(track.location))
url = QUrl.fromLocalFile(track.location)
if self._media.source() == url:
# setSource() no-ops on an unchanged URL, so LoadedMedia never
# re-fires and the armed start time would be skipped (and forcing
# a clear+reload races the FFmpeg backend, which snaps the seek
# back to 0). The media is already loaded: rewind and seek now.
self._media.stop()
if self._pending_start_ms:
self._media.setPosition(self._pending_start_ms)
self._pending_start_ms = 0
else:
self._media.setSource(url)
if autoplay:
self._media.play()
self.track_changed.emit(track)