Skip to content

Native Android client for Spotify, built with Jetpack Compose

The greyed Cast devices under a Spotify song now say what Cast plays (downloaded, extension and phone songs) and that a Spotify song needs the device to appear in Spotify Connect (translated); the Cast discovery no longer stays stuck resolving a device that never answers: a resolution is given up after 5 s, and stopping the discovery drops the one in flight [skip ci]

kota-zo8cb9417d1132
diff --git a/base/app/src/main/java/com/music/spotui/cast/CastDiscovery.kt b/base/app/src/main/java/com/music/spotui/cast/CastDiscovery.kt
index 1b20b135..4b95b897 100644
--- a/base/app/src/main/java/com/music/spotui/cast/CastDiscovery.kt
+++ b/base/app/src/main/java/com/music/spotui/cast/CastDiscovery.kt
@@ -29,6 +29,15 @@ object CastDiscovery {
/** Before Android 14 NsdManager resolves one service at a time: the others wait here. */
private val waiting = ArrayDeque<NsdServiceInfo>()
private var resolving = false
+ /** Counts the resolutions: a late answer of one given up (or cut by [stop]) does not end the next one. */
+ private var round = 0
+ /** A resolution that never answers (seen before Android 14) is given up after this, or no device would ever be listed. */
+ private const val RESOLVE_GUARD_MS = 5_000L
+ private val resolveGuard = Runnable {
+ log("a Cast device did not resolve in ${RESOLVE_GUARD_MS / 1000} s: moving on")
+ resolving = false
+ next()
+ }
/** Starts looking (each [start] wants one [stop]). Main thread. */
fun start(context: Context) {
@@ -62,6 +71,10 @@ object CastDiscovery {
listener?.let { l -> runCatching { nsd?.stopServiceDiscovery(l) } }
listener = null
waiting.clear()
+ // A resolution in flight is left behind: a later start must not wait for its answer.
+ main.removeCallbacks(resolveGuard)
+ resolving = false
+ round++
}
@Suppress("DEPRECATION")
@@ -70,7 +83,14 @@ object CastDiscovery {
val info = waiting.removeFirstOrNull() ?: return
val m = nsd ?: return
resolving = true
- val done = { main.post { resolving = false; next() }; Unit }
+ val mine = ++round
+ main.postDelayed(resolveGuard, RESOLVE_GUARD_MS)
+ val done = {
+ main.post {
+ if (round == mine && resolving) { main.removeCallbacks(resolveGuard); resolving = false; next() }
+ }
+ Unit
+ }
runCatching {
m.resolveService(info, object : NsdManager.ResolveListener {
override fun onResolveFailed(serviceInfo: NsdServiceInfo, errorCode: Int) {
diff --git a/base/app/src/main/res/values-de/myspoti_strings.xml b/base/app/src/main/res/values-de/myspoti_strings.xml
index 6365d331..cd735434 100644
--- a/base/app/src/main/res/values-de/myspoti_strings.xml
+++ b/base/app/src/main/res/values-de/myspoti_strings.xml
@@ -558,7 +558,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">Wiedergabe auf %1$s nicht möglich</string>
<string name="cast_lost">Verbindung zu %1$s verloren: zurück auf diesem Handy</string>
- <string name="cast_spotify_via_connect">Spotify-Songs laufen auf Cast-Geräten über Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Cast spielt heruntergeladene Titel, Titel von Erweiterungen und Titel vom Handy. Für einen Spotify-Titel muss das Gerät in Spotify Connect erscheinen.</string>
<string name="downloads_need_source_detail">Songs werden von Erweiterungen heruntergeladen. Noch ist keine installiert: Öffne den Erweiterungs-Store und installiere Mornye, um herunterzuladen.</string>
<string name="downloads_need_source_title">Downloads brauchen eine Erweiterung</string>
<string name="episode_new">Neu</string>
diff --git a/base/app/src/main/res/values-el/myspoti_strings.xml b/base/app/src/main/res/values-el/myspoti_strings.xml
index f31256a9..31eb3248 100644
--- a/base/app/src/main/res/values-el/myspoti_strings.xml
+++ b/base/app/src/main/res/values-el/myspoti_strings.xml
@@ -558,7 +558,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">Δεν ήταν δυνατή η αναπαραγωγή στο %1$s</string>
<string name="cast_lost">Χάθηκε η σύνδεση με %1$s: ξανά σε αυτό το τηλέφωνο</string>
- <string name="cast_spotify_via_connect">Τα τραγούδια του Spotify παίζουν σε συσκευές Cast μέσω Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Το Cast παίζει τραγούδια που έχουν γίνει λήψη, από επεκτάσεις και από το τηλέφωνο. Για ένα τραγούδι του Spotify, η συσκευή πρέπει να εμφανίζεται στο Spotify Connect.</string>
<string name="downloads_need_source_detail">Τα τραγούδια κατεβαίνουν από επεκτάσεις. Δεν έχει εγκατασταθεί καμία ακόμα: ανοίξτε το κατάστημα επεκτάσεων και εγκαταστήστε το Mornye για λήψεις.</string>
<string name="downloads_need_source_title">Οι λήψεις χρειάζονται επέκταση</string>
<string name="episode_new">Νέο</string>
diff --git a/base/app/src/main/res/values-es/myspoti_strings.xml b/base/app/src/main/res/values-es/myspoti_strings.xml
index a24c06f1..7d2b4cdb 100644
--- a/base/app/src/main/res/values-es/myspoti_strings.xml
+++ b/base/app/src/main/res/values-es/myspoti_strings.xml
@@ -558,7 +558,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">No se pudo reproducir en %1$s</string>
<string name="cast_lost">Se perdió %1$s: de vuelta en este teléfono</string>
- <string name="cast_spotify_via_connect">Las canciones de Spotify suenan en los dispositivos Cast a través de Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Cast reproduce las canciones descargadas, de extensiones y del teléfono. Para una canción de Spotify, el dispositivo debe aparecer en Spotify Connect.</string>
<string name="downloads_need_source_detail">Las canciones se descargan con extensiones. Aún no hay ninguna instalada: abre la tienda de extensiones e instala Mornye para descargar.</string>
<string name="downloads_need_source_title">Las descargas necesitan una extensión</string>
<string name="episode_new">Nuevo</string>
diff --git a/base/app/src/main/res/values-fr/myspoti_strings.xml b/base/app/src/main/res/values-fr/myspoti_strings.xml
index bb7d8ff9..2040636b 100644
--- a/base/app/src/main/res/values-fr/myspoti_strings.xml
+++ b/base/app/src/main/res/values-fr/myspoti_strings.xml
@@ -565,7 +565,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">Impossible de lire sur %1$s</string>
<string name="cast_lost">%1$s perdu : retour sur ce téléphone</string>
- <string name="cast_spotify_via_connect">Les titres Spotify passent sur les appareils Cast par Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Le Cast joue les titres téléchargés, d\'extensions et du téléphone. Pour un titre Spotify, l\'appareil doit apparaître dans Spotify Connect.</string>
<string name="downloads_need_source_detail">Les titres sont téléchargés par des extensions. Aucune n\'est installée : ouvrez le store des extensions et installez Mornye pour télécharger.</string>
<string name="downloads_need_source_title">Les téléchargements demandent une extension</string>
<string name="episode_new">Nouveau</string>
diff --git a/base/app/src/main/res/values-it/myspoti_strings.xml b/base/app/src/main/res/values-it/myspoti_strings.xml
index 79346d43..ed7aef44 100644
--- a/base/app/src/main/res/values-it/myspoti_strings.xml
+++ b/base/app/src/main/res/values-it/myspoti_strings.xml
@@ -558,7 +558,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">Impossibile riprodurre su %1$s</string>
<string name="cast_lost">%1$s perso: di nuovo su questo telefono</string>
- <string name="cast_spotify_via_connect">I brani Spotify vengono riprodotti sui dispositivi Cast tramite Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Cast riproduce i brani scaricati, delle estensioni e del telefono. Per un brano Spotify, il dispositivo deve comparire in Spotify Connect.</string>
<string name="downloads_need_source_detail">I brani vengono scaricati dalle estensioni. Non ne è ancora installata nessuna: apri lo store delle estensioni e installa Mornye per scaricare.</string>
<string name="downloads_need_source_title">I download richiedono un\'estensione</string>
<string name="episode_new">Nuovo</string>
diff --git a/base/app/src/main/res/values-pl/myspoti_strings.xml b/base/app/src/main/res/values-pl/myspoti_strings.xml
index 888deac1..66aa3409 100644
--- a/base/app/src/main/res/values-pl/myspoti_strings.xml
+++ b/base/app/src/main/res/values-pl/myspoti_strings.xml
@@ -569,7 +569,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">Nie udało się odtworzyć na %1$s</string>
<string name="cast_lost">Utracono %1$s: z powrotem na tym telefonie</string>
- <string name="cast_spotify_via_connect">Utwory Spotify grają na urządzeniach Cast przez Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Cast odtwarza pobrane utwory, utwory z rozszerzeń i z telefonu. Utwór ze Spotify wymaga, by urządzenie było widoczne w Spotify Connect.</string>
<string name="downloads_need_source_detail">Utwory pobierają rozszerzenia. Żadne nie jest jeszcze zainstalowane: otwórz sklep z rozszerzeniami i zainstaluj Mornye, aby pobierać.</string>
<string name="downloads_need_source_title">Pobieranie wymaga rozszerzenia</string>
<string name="episode_new">Nowy</string>
diff --git a/base/app/src/main/res/values-pt/myspoti_strings.xml b/base/app/src/main/res/values-pt/myspoti_strings.xml
index b78fcf81..e7fd5bfd 100644
--- a/base/app/src/main/res/values-pt/myspoti_strings.xml
+++ b/base/app/src/main/res/values-pt/myspoti_strings.xml
@@ -558,7 +558,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">Não foi possível tocar em %1$s</string>
<string name="cast_lost">%1$s perdido: de volta neste celular</string>
- <string name="cast_spotify_via_connect">As músicas do Spotify tocam em dispositivos Cast pelo Spotify Connect</string>
+ <string name="cast_spotify_via_connect">O Cast toca músicas baixadas, de extensões e do celular. Para uma música do Spotify, o dispositivo precisa aparecer no Spotify Connect.</string>
<string name="downloads_need_source_detail">As músicas são baixadas por extensões. Nenhuma está instalada ainda: abra a loja de extensões e instale o Mornye para baixar.</string>
<string name="downloads_need_source_title">Os downloads precisam de uma extensão</string>
<string name="episode_new">Novo</string>
diff --git a/base/app/src/main/res/values-ru/myspoti_strings.xml b/base/app/src/main/res/values-ru/myspoti_strings.xml
index 7e2d9493..8a80aa3c 100644
--- a/base/app/src/main/res/values-ru/myspoti_strings.xml
+++ b/base/app/src/main/res/values-ru/myspoti_strings.xml
@@ -569,7 +569,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">Не удалось воспроизвести на %1$s</string>
<string name="cast_lost">Связь с %1$s потеряна: снова на этом телефоне</string>
- <string name="cast_spotify_via_connect">Треки Spotify играют на устройствах Cast через Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Cast воспроизводит загруженные треки, треки из расширений и с телефона. Чтобы играл трек Spotify, устройство должно появиться в Spotify Connect.</string>
<string name="downloads_need_source_detail">Треки скачивают расширения. Пока ни одно не установлено: откройте магазин расширений и установите Mornye, чтобы скачивать.</string>
<string name="downloads_need_source_title">Для загрузок нужно расширение</string>
<string name="episode_new">Новый</string>
diff --git a/base/app/src/main/res/values-zh/myspoti_strings.xml b/base/app/src/main/res/values-zh/myspoti_strings.xml
index c3456586..73fc75c2 100644
--- a/base/app/src/main/res/values-zh/myspoti_strings.xml
+++ b/base/app/src/main/res/values-zh/myspoti_strings.xml
@@ -560,7 +560,7 @@
<string name="cast_device_detail">Google Cast</string>
<string name="cast_failed">无法在 %1$s 上播放</string>
<string name="cast_lost">与 %1$s 的连接已断开:回到本手机播放</string>
- <string name="cast_spotify_via_connect">Spotify 歌曲通过 Spotify Connect 在 Cast 设备上播放</string>
+ <string name="cast_spotify_via_connect">Cast 可播放已下载、来自扩展和手机上的歌曲。播放 Spotify 歌曲时,设备需要出现在 Spotify Connect 中。</string>
<string name="downloads_need_source_detail">歌曲由扩展下载。目前尚未安装任何扩展:打开扩展商店并安装 Mornye 即可下载。</string>
<string name="downloads_need_source_title">下载需要扩展</string>
<string name="episode_new">新</string>
diff --git a/base/app/src/main/res/values/myspoti_strings.xml b/base/app/src/main/res/values/myspoti_strings.xml
index 575b841a..87a4616c 100644
--- a/base/app/src/main/res/values/myspoti_strings.xml
+++ b/base/app/src/main/res/values/myspoti_strings.xml
@@ -582,7 +582,7 @@
<string name="aa_library">Library</string>
<string name="aa_downloads">Downloads</string>
<string name="cast_device_detail">Google Cast</string>
- <string name="cast_spotify_via_connect">Spotify songs play on Cast devices through Spotify Connect</string>
+ <string name="cast_spotify_via_connect">Cast plays your downloaded, extension and phone songs. For a Spotify song, the device must appear in Spotify Connect.</string>
<string name="cast_connecting">Connecting…</string>
<string name="cast_failed">Could not play on %1$s</string>
<string name="cast_lost">Lost %1$s: back on this phone</string>