forked from trav/lintunes
v0.56.0: Connect to AirPlay — stream to AirPlay speakers via pyatv
Every song is decoded by the ffmpeg CLI and streamed over RAOP, so ALAC and AIFF play too (only FairPlay is refused). pyatv has no pause or seek for RAOP, so both restart the stream at the heard position. The picker lists every AirPlay device on the network, greyed with the reason when LinTunes can't stream to it (video-only TVs, PIN pairing). Casting and AirPlay are mutually exclusive; the visualizer tile shows the AirPlay glyph and a click there stops it. Needs: pip install -e . (adds pyatv).
This commit is contained in:
+52
-15
@@ -15,6 +15,7 @@ from lintunes.andtunes import layout as andtunes_layout
|
||||
from lintunes.andtunes import install as andtunes_install
|
||||
from lintunes.andtunes import sync as andtunes_sync
|
||||
from lintunes.art_search import AlbumArtFetcher
|
||||
from lintunes.airplay.controller import AirPlayController
|
||||
from lintunes.cast.controller import CastController
|
||||
from lintunes.eventlog import log_control
|
||||
from lintunes.config import load_config, save_config
|
||||
@@ -26,7 +27,7 @@ from lintunes.storage import listen_history
|
||||
from lintunes.importers import file_importer
|
||||
from lintunes.gui.album_art_dialog import AlbumArtDialog
|
||||
from lintunes.gui.art_ops import embed_artwork
|
||||
from lintunes.gui.cast_dialog import ChromecastDialog
|
||||
from lintunes.gui.cast_dialog import AirPlayDialog, ChromecastDialog
|
||||
from lintunes.gui.cassette_ui import CassetteUi
|
||||
from lintunes.gui import sounds
|
||||
from lintunes.gui.device_sync_dialog import (
|
||||
@@ -120,6 +121,9 @@ class MainWindow(QMainWindow):
|
||||
# Owns the cast session, if any. Built before the transport bar, which
|
||||
# takes it to drive the little cast indicator under the volume slider.
|
||||
self._cast = CastController(self.player, self)
|
||||
# The same for AirPlay. At most one of the two is ever connected:
|
||||
# connecting either disconnects the other first.
|
||||
self._airplay = AirPlayController(self.player, self)
|
||||
# Where the Rabbit is, found off the GUI thread: a wedged gvfs-MTP
|
||||
# mount blocks any listing of it forever (Round 71). Nothing probes
|
||||
# until the Connections menu opens.
|
||||
@@ -152,7 +156,7 @@ class MainWindow(QMainWindow):
|
||||
self.setCentralWidget(central)
|
||||
|
||||
self._transport = TransportBar(self.player, manager, self._prefs,
|
||||
cast=self._cast)
|
||||
cast=self._cast, airplay=self._airplay)
|
||||
layout.addWidget(self._transport)
|
||||
|
||||
splitter = QSplitter(Qt.Orientation.Horizontal)
|
||||
@@ -329,6 +333,15 @@ class MainWindow(QMainWindow):
|
||||
self._cast.disconnected.connect(self._on_cast_disconnected)
|
||||
self._cast.failed.connect(
|
||||
lambda msg: QMessageBox.warning(self, "Chromecast", msg))
|
||||
self._airplay.connecting.connect(self._on_cast_connecting)
|
||||
self._airplay.connected.connect(
|
||||
lambda name: self.statusBar().showMessage(
|
||||
f"Playing on {name} (AirPlay)", 6000))
|
||||
self._airplay.disconnected.connect(
|
||||
lambda reason: self.statusBar().showMessage(
|
||||
reason or "Stopped AirPlay — playing here again", 8000))
|
||||
self._airplay.failed.connect(
|
||||
lambda msg: QMessageBox.warning(self, "AirPlay", msg))
|
||||
manager.library_reloaded.connect(self._on_library_reloaded)
|
||||
manager.conflict_resolved.connect(self._on_conflict_resolved)
|
||||
prefs.changed.connect(self._on_prefs_changed)
|
||||
@@ -492,6 +505,8 @@ class MainWindow(QMainWindow):
|
||||
self._cassette.build_menu(connections_menu)
|
||||
self._cast_action = self._add_action(
|
||||
connections_menu, "Connect to Chromecast…", "", self._toggle_cast)
|
||||
self._airplay_action = self._add_action(
|
||||
connections_menu, "Connect to AirPlay…", "", self._toggle_airplay)
|
||||
# Re-checked every time the menu opens. The device part is a
|
||||
# background probe; its answer updates the open menu when it lands.
|
||||
connections_menu.aboutToShow.connect(self._refresh_connection_actions)
|
||||
@@ -565,19 +580,22 @@ class MainWindow(QMainWindow):
|
||||
and not (self._install_worker is not None
|
||||
and self._install_worker.busy()))
|
||||
|
||||
if self._cast.is_connected():
|
||||
self._cast_action.setText(
|
||||
f"Disconnect from {self._cast.device_name()}")
|
||||
self._cast_action.setEnabled(True)
|
||||
self._cast_action.setToolTip("")
|
||||
return
|
||||
self._cast_action.setText("Connect to Chromecast…")
|
||||
available, why = self._cast.is_available()
|
||||
self._cast_action.setEnabled(available)
|
||||
# The self-updater ships code but not dependencies, so a machine that
|
||||
# has pulled this round hasn't necessarily installed pychromecast yet.
|
||||
self._cast_action.setToolTip(
|
||||
"" if available else f"{why} — run: pip install -e .")
|
||||
# has pulled this round hasn't necessarily installed pychromecast (or
|
||||
# pyatv) yet.
|
||||
for action, controller, text in (
|
||||
(self._cast_action, self._cast, "Connect to Chromecast…"),
|
||||
(self._airplay_action, self._airplay, "Connect to AirPlay…")):
|
||||
if controller.is_connected():
|
||||
action.setText(f"Disconnect from {controller.device_name()}")
|
||||
action.setEnabled(True)
|
||||
action.setToolTip("")
|
||||
continue
|
||||
action.setText(text)
|
||||
available, why = controller.is_available()
|
||||
action.setEnabled(available)
|
||||
action.setToolTip(
|
||||
"" if available else f"{why} — run: pip install -e .")
|
||||
|
||||
# ---- connections: casting ----
|
||||
|
||||
@@ -594,8 +612,25 @@ class MainWindow(QMainWindow):
|
||||
return
|
||||
dialog = ChromecastDialog(self._cast.discovery(), self)
|
||||
if dialog.exec() and dialog.selected_device is not None:
|
||||
self._airplay.disconnect()
|
||||
self._cast.connect_to(dialog.selected_device)
|
||||
|
||||
def _toggle_airplay(self):
|
||||
if self._airplay.is_connected():
|
||||
self._airplay.disconnect()
|
||||
return
|
||||
available, why = self._airplay.is_available()
|
||||
if not available:
|
||||
QMessageBox.information(
|
||||
self, "AirPlay support not installed",
|
||||
f"{why}.\n\nRun “pip install -e .” in the lintunes checkout "
|
||||
"(and install ffmpeg if it's missing), then restart LinTunes.")
|
||||
return
|
||||
dialog = AirPlayDialog(self._airplay.discovery(), self)
|
||||
if dialog.exec() and dialog.selected_device is not None:
|
||||
self._cast.disconnect()
|
||||
self._airplay.connect_to(dialog.selected_device)
|
||||
|
||||
def _on_cast_connecting(self, device):
|
||||
self.statusBar().showMessage(f"Connecting to {device.name}…", 8000)
|
||||
|
||||
@@ -2270,7 +2305,8 @@ class MainWindow(QMainWindow):
|
||||
self._manager.record_listen(listen_history.entry_for(
|
||||
track, started=started or listen_history.local_now(),
|
||||
heard_ms=heard_ms, how=how,
|
||||
src="desktop" if self.player.is_local else "cast",
|
||||
src=("desktop" if self.player.is_local else
|
||||
getattr(self.player.active_sink(), "listen_src", "cast")),
|
||||
ctx=ctx, shuffle=self.player.is_shuffle(),
|
||||
track_id=None if isinstance(key, str) else key))
|
||||
|
||||
@@ -2384,6 +2420,7 @@ class MainWindow(QMainWindow):
|
||||
# is fetching from. Skipped, the Chromecast sits buffering a dead URL.
|
||||
self._cassette.shutdown()
|
||||
self._cast.shutdown()
|
||||
self._airplay.shutdown()
|
||||
self.player.shutdown()
|
||||
self.player.loudness.save()
|
||||
self._manager.flush()
|
||||
|
||||
Reference in New Issue
Block a user