v0.4.0: cast to a Chromecast from the Connections menu

The Device menu becomes Connections, with "Connect to Chromecast…" beside
the Rabbit sync. It opens a dialog that spins while it searches and lists
devices as they appear; picking one hands playback over, puts a small cast
glyph under the volume slider, and clicking that glyph disconnects.

Media-receiver model: lintunes serves the original file over the LAN on an
ephemeral port and the Chromecast decodes it itself. Bit-exact — no
transcode, no second lossy encode — and the device buffers for itself. The
cost is that lintunes is a remote control while connected: no local PCM, so
the visualizer shows the cast glyph instead of bars, and transport actions
land with about a second of round trip.

Player now walks its queue through a swappable PlaybackSink. It keeps
owning the queue, shuffle walk, start/stop times and the play-count and
scrobble bookkeeping, so casting counts plays and scrobbles exactly like
local playback. set_sink() carries track, position and playing-state both
ways, so connecting and disconnecting pick up mid-song. LocalSink stays in
player.py because the Player tests stub Qt Multimedia in that namespace.

The URL carries an opaque random token, never a path, so there is nothing
to traverse with; only the last few played tracks stay resolvable and the
whole map dies with the session. Range and HEAD are implemented because
the device seeks by re-requesting ranges and won't report a duration
without them.

Failure handling, verified against a real device: a dropped socket gets a
15s grace period, since pychromecast retries on its own and a Wi-Fi blip
heals itself. A real loss, another app taking the device, or a network
change falls back to local playback still playing, at the same position —
the sink reports the state lintunes last asked for rather than the IDLE
status a dying connection pushes just before it goes. Quitting stops the
device instead of leaving it fetching from a server that just died. The
~119 Apple Lossless / AIFF / protected-AAC tracks are skipped with a
status-bar message; the other 21,000+ MP3 and AAC files cast natively.

New dependency: pychromecast>=14.0.10, imported lazily so the app still
launches where it isn't installed (the menu item then explains the
install), and python_requires raised to >=3.11 to match its floor.

NOTE: the other machine needs `pip install -e .` before casting appears.

tests/test_round29.py: 67 tests; 440 pass overall.
This commit is contained in:
2026-08-13 21:49:53 -04:00
parent 4a3c66e7ff
commit a42665cacc
26 changed files with 2885 additions and 209 deletions
+22 -4
View File
@@ -8,6 +8,7 @@ from PyQt6.QtCore import Qt, QTimer, pyqtSignal
from PyQt6.QtGui import QColor, QFont
from lintunes.tap_tempo import TapTempo
from lintunes.gui.cast_indicator import CastIndicator
from lintunes.gui.icons import transport_icon
from lintunes.gui.track_table import format_time
from lintunes.gui.visualizer import VisualizerWidget
@@ -234,10 +235,11 @@ class TransportBar(QWidget):
play_clicked = pyqtSignal() # MainWindow decides what "play" means
def __init__(self, player, manager, prefs, parent=None):
def __init__(self, player, manager, prefs, cast=None, parent=None):
super().__init__(parent)
self._player = player
self._prefs = prefs
self._cast = cast
self._scrubbing = False
self._current_track = None
@@ -280,8 +282,9 @@ class TransportBar(QWidget):
layout.addSpacing(10)
# Master output volume: a slim horizontal slider in its own slot
# between the visualizer and the timeline. The HBox centers it
# vertically, so nothing stacks above or below it (iTunes-style).
# between the visualizer and the timeline, with the cast indicator
# parked directly beneath it. The column is shorter than the boxes
# beside it, so the HBox still centers it and BAR_HEIGHT is untouched.
self._volume_slider = ClickJumpSlider()
self._volume_slider.setRange(0, 100)
self._volume_slider.setFixedWidth(96)
@@ -297,7 +300,15 @@ class TransportBar(QWidget):
self._volume_save_timer.setInterval(400)
self._volume_save_timer.timeout.connect(self._save_volume)
self._volume_slider.valueChanged.connect(self._on_volume_changed)
layout.addWidget(self._volume_slider)
volume_col = QVBoxLayout()
volume_col.setSpacing(2)
volume_col.setContentsMargins(0, 0, 0, 0)
volume_col.addWidget(self._volume_slider,
alignment=Qt.AlignmentFlag.AlignHCenter)
self._cast_indicator = CastIndicator()
volume_col.addWidget(self._cast_indicator,
alignment=Qt.AlignmentFlag.AlignHCenter)
layout.addLayout(volume_col)
layout.addSpacing(10)
center = QVBoxLayout()
@@ -365,6 +376,12 @@ class TransportBar(QWidget):
player.playing_changed.connect(self._on_playing_changed)
player.position_changed.connect(self._on_position_changed)
player.duration_changed.connect(self._on_duration_changed)
if cast is not None:
cast.connected.connect(
lambda name: self._cast_indicator.set_connected(True, name))
cast.disconnected.connect(
lambda _reason: self._cast_indicator.set_connected(False))
self._cast_indicator.clicked.connect(lambda: cast.disconnect())
def refresh_theme(self):
"""Re-apply everything driven by Preferences: button glyphs (highlight
@@ -378,6 +395,7 @@ class TransportBar(QWidget):
box.setStyleSheet(_box_style(box_bg))
self._apply_now_playing_bg()
self._apply_now_playing_font()
self._cast_indicator.refresh_theme()
self._visualizer.update() # dim-mode bar color may have changed
def _apply_now_playing_bg(self):