Fix silent resume after walking away: seek-in-place re-primes the sink
Rediagnosed (was thought Bluetooth-specific): on the Debian 13 machine, resuming after the machine sat idle plays nothing even though decoding runs (visualizer moves) — the OS suspends the audio sink and it comes back dead until a seek re-primes it. Resuming after a pause of 30s+ now does a seek-in-place before play(), automating the manual "rewind slightly" workaround without losing the position. The volume re-apply from the earlier fix stays (harmless, covers device swaps). Also fold the new backlog items into the TASKS.md board. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import random
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from PyQt6.QtCore import QObject, QUrl, pyqtSignal
|
||||
@@ -11,6 +12,12 @@ from lintunes.models import Track
|
||||
# Hitting "previous" more than this far into a song restarts it instead
|
||||
RESTART_THRESHOLD_MS = 3000
|
||||
|
||||
# Resuming after a pause at least this long does a seek-in-place first: when
|
||||
# the machine sits idle, the OS suspends the audio sink and it can come back
|
||||
# silently dead — decoding continues (the visualizer moves) but nothing is
|
||||
# audible until a seek re-primes the sink. Seen on trav's Debian 13 machine.
|
||||
RESUME_NUDGE_THRESHOLD_S = 30
|
||||
|
||||
|
||||
def make_shuffle_order(count: int, start_index: int) -> list[int]:
|
||||
"""A random permutation of range(count) that begins at start_index."""
|
||||
@@ -51,6 +58,7 @@ class Player(QObject):
|
||||
self._pending_start_ms = 0
|
||||
self._stop_at_ms = 0
|
||||
self._counted_finish_id: int | None = None
|
||||
self._paused_at: float | None = None # monotonic time of last pause
|
||||
|
||||
self._audio = QAudioOutput(self)
|
||||
self._volume = 1.0 # logical 0..1; what the volume slider shows
|
||||
@@ -190,9 +198,18 @@ class Player(QObject):
|
||||
|
||||
def toggle_play(self):
|
||||
if self.is_playing():
|
||||
self._paused_at = time.monotonic()
|
||||
self._media.pause()
|
||||
elif self._current_track is not None:
|
||||
self._apply_volume()
|
||||
if (self._paused_at is not None
|
||||
and time.monotonic() - self._paused_at
|
||||
>= RESUME_NUDGE_THRESHOLD_S):
|
||||
# Re-prime a possibly idle-suspended sink (the manual
|
||||
# workaround was "rewind slightly"); seek in place so the
|
||||
# listener doesn't lose their spot.
|
||||
self._media.setPosition(self._media.position())
|
||||
self._paused_at = None
|
||||
self._media.play()
|
||||
elif self._queue:
|
||||
self._index = max(self._index, 0)
|
||||
@@ -204,6 +221,7 @@ class Player(QObject):
|
||||
|
||||
def pause(self):
|
||||
if self.is_playing():
|
||||
self._paused_at = time.monotonic()
|
||||
self._media.pause()
|
||||
|
||||
def stop(self):
|
||||
|
||||
Reference in New Issue
Block a user